Afshartous, David
2010-Jun-02 18:34 UTC
[R] pdf function, resize xyplot plot automatically
All, When saving plots to a pdf file via the pdf function, I would like to be able to automatically expand the graphics device to achieve the same result as when one does this manually (e.g., clicking the green expand button on the upper left of the graph on Mac OS). Consider simple example below: library("lattice") foo.frm = data.frame(Subject = rep(c(1:4), each = 9), Y = rnorm(36), Time rep(c( 0, 15, 30, 45, 60, 90, 150, 210, 270), 4)) xyplot(Y ~ Time | as.factor(Subject), data = foo.frm, scale = list(x list(at = c(0, 15, 30, 45, 60, 90, 150, 210, 270)))) The tick marks are very close but this is resolved by expanding the graphics device as mentioned above. However, in the code below the file that is created by the pdf function is created w/o such an adjustment. I suppose one could work around this via changing the number of tick marks, but if there was a way to automatically achieve the expansion of the graph as when done manually that would be great. Any tips much appreciated. pdf(file = "foo.pdf", onefile = T) xyplot(Y ~ Time | as.factor(Subject), data = foo.frm, scale = list(x list(at = c(0, 15, 30, 45, 60, 90, 150, 210, 270)))) dev.off() Thanks, David -------------------------------------- David Afshartous, Ph.D. Research Assistant Professor University of Miami, Miller School of Medicine Division of Clinical Pharmacology 1500 N.W. 12th Avenue, 15th Floor West Miami, Florida 33136 E-mail: afshar at med.miami.edu Phone: +1 305-243-1549
David, I would use either the 'width=' argument to pdf() or use a smaller font for the x-axis (or both). Something like: pdf(file = "foo.pdf", width = 10) xyplot(Y ~ Time | as.factor(Subject), data = foo.frm, layout = c(2,2), scale = list(x = list( at = c(0, 15, 30, 45, 60, 90, 150, 210, 270), cex = 0.7))) dev.off() -Peter Ehlers On 2010-06-02 12:34, Afshartous, David wrote:> > All, > > When saving plots to a pdf file via the pdf function, I would like to be > able to automatically expand the graphics device to achieve the same result > as when one does this manually (e.g., clicking the green expand button on > the upper left of the graph on Mac OS). Consider simple example below: > > > library("lattice") > foo.frm = data.frame(Subject = rep(c(1:4), each = 9), Y = rnorm(36), Time > rep(c( 0, 15, 30, 45, 60, 90, 150, 210, 270), 4)) > xyplot(Y ~ Time | as.factor(Subject), data = foo.frm, scale = list(x > list(at = c(0, 15, 30, 45, 60, 90, 150, 210, 270)))) > > The tick marks are very close but this is resolved by expanding the graphics > device as mentioned above. However, in the code below the file that is > created by the pdf function is created w/o such an adjustment. I suppose > one could work around this via changing the number of tick marks, but if > there was a way to automatically achieve the expansion of the graph as when > done manually that would be great. Any tips much appreciated. > > > pdf(file = "foo.pdf", onefile = T) > xyplot(Y ~ Time | as.factor(Subject), data = foo.frm, scale = list(x > list(at = c(0, 15, 30, 45, 60, 90, 150, 210, 270)))) > dev.off() > > > Thanks, > David > > -------------------------------------- > David Afshartous, Ph.D. > Research Assistant Professor > University of Miami, Miller School of Medicine > Division of Clinical Pharmacology > 1500 N.W. 12th Avenue, 15th Floor West > Miami, Florida 33136 > > E-mail: afshar at med.miami.edu > Phone: +1 305-243-1549 >
On Wed, 02-Jun-2010 at 02:34PM -0400, Afshartous, David wrote: |> |> All, |> |> When saving plots to a pdf file via the pdf function, I would like to be |> able to automatically expand the graphics device to achieve the same result |> as when one does this manually (e.g., clicking the green expand button on |> the upper left of the graph on Mac OS). Consider simple example below: If it's a file you want to keep, it makes more sense IMHO to keep a record of just what you did to get the size you want. For that reason, it's a better idea to set the width &/or height in the call to pdf(). Peter Ehlers has told you how to use the 'width' argument. For interactive use, the normal X11 window can be resized in the way you would probably like. I quite like the way R offers you two quite different ways of doing such things. [...] HTH -- ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. ___ Patrick Connolly {~._.~} Great minds discuss ideas _( Y )_ Average minds discuss events (:_~*~_:) Small minds discuss people (_)-(_) ..... Eleanor Roosevelt ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.