Paul E Johnson
2000-Aug-17 07:14 UTC
[R] Things I don't understand about the graphics interface
Using R-1.1.1 on RedHatLinux 6.2. I've made some progress, succeeded in outputting bitmap, jpeg, and png files. Yipee. I did them with this command:> dev2bitmap("whatever.bmp",res=300) > dev.print(png, file="myplot.png", width=480, height=480) > dev.print(jpeg, file="myplot.jpg", width=480, height=480) > dev.print(pictex, file="myplot.tex", width=480, height=480)Now here are the things I don't understand about the docs and/or this interface. I understand these functions have undergone change... 1. Why is there a separate method dev.copy2eps. To be consistent, shouldn't we be able to do> dev.print(eps, ...)and why does bitmap format have dev2bitmap, rather than dev.print(bitmap, ...)? When I tried that once like so:> dev.print(bitmap, file="myplot.jpg", width=480, height=480)R churned way, running and writing and never stopping. Then I did it again, just for fun, and I got:> dev.print(bitmap, file="myplot.jpg", width=480, height=480)Error in dev.print(bitmap, file = "myplot.jpg", width = 480, height 480) : can only print from screen device>2. Do png and jpeg usage inherit the paper size, width, and height set by the postscript() or ps.options(). 3. I see that png() and jpeg() have no "horizontal" option. Is that because they are being saved in a file, and there is no need to constrain them to fit in a piece of paper? 4. Can you explain this? I did>example(hist)and a bunch of histograms flew by really fast. Then I did> png(file="test.png") > example(hist) > dev.off()I expected the file "test.png" to have just one figure, I was guessing the last one that showed on the screen. But instead it was a figure with 4 histograms, arrayed in a 2x2 matrix. What controlled that? png() has no option like onefile=FALSE. 5. I wish there was "maximum aspect-ratio preserving" adjustment for size. If I'm looking at a graph on the screen, and I like it, except it is too big, I'd like to specify a width and have R assume the corresponding height. Otherwise, when I try to specify height and width, R tries to stretch the objects being drawn and it looks like hell. It is important to make this adjustment inside R, I think, in order to keep the figure looking nice and to avoid scaling it in the Gimp or something. 6. The commands above suceeded with R-1.1.1 on RedHat 6.2, but with R-1.1 on RedHat 6.1, I did the same things and the png and jpeg images were corrupted/unviewable every time. Is this likely due to different versions of X or ghostscript? -- Paul E. Johnson email: pauljohn at ukans.edu Dept. of Political Science http://lark.cc.ukans.edu/~pauljohn University of Kansas Office: (785) 864-9086 Lawrence, Kansas 66045 FAX: (785) 864-5700 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Prof Brian D Ripley
2000-Aug-17 08:55 UTC
[R] Things I don't understand about the graphics interface
On Thu, 17 Aug 2000, Paul E Johnson wrote:> Using R-1.1.1 on RedHatLinux 6.2. > I've made some progress, succeeded in outputting bitmap, jpeg, and png > files. Yipee. > > I did them with this command: > > dev2bitmap("whatever.bmp",res=300) > > dev.print(png, file="myplot.png", width=480, height=480) > > dev.print(jpeg, file="myplot.jpg", width=480, height=480) > > dev.print(pictex, file="myplot.tex", width=480, height=480) > > Now here are the things I don't understand about the docs and/or this > interface. I understand these functions have undergone change...Not fundamentally since 1.1. Could you try reading ?bitmap and ?png and noting the differences? Also, you do seem to be confusing printing to a sheet of paper with producing a plot in a graphics format. The latter just encodes the plot region at the size and shape specified by width and height. The former places the plot region within the paper region. You seem to be reading into the docs things I think are just not there, not should be.> 1. Why is there a separate method dev.copy2eps. To be consistent, > shouldn't we be able to do > > dev.print(eps, ...)Because that is not printing, as in send to a printer. dev.print is designed to print to a papersize, dev.copy2eps to copy an abstract bounding box as specified or taken from the on-screen device. I think your examples should be using dev.copy, not dev.print.> and why does bitmap format have dev2bitmap, rather than > dev.print(bitmap, ...)?You can use either (on Unix at least). dev2bitmap predates bitmap, which relies on piping output that was not supported until recently.> When I tried that once like so: > > dev.print(bitmap, file="myplot.jpg", width=480, height=480) > R churned way, running and writing and never stopping. Then I did it > again, just for fun, and I got:When you interrupted it (you must have), you left a postscript device open, hence> > dev.print(bitmap, file="myplot.jpg", width=480, height=480) > Error in dev.print(bitmap, file = "myplot.jpg", width = 480, height > 480) : > can only print from screen deviceYour problem is that you asked for a 480x480inch plot at 72dpi, and I doubt you have the resources for that! For me dev.print(bitmap, file="myplot.jpg", width=6, height=6) works. You could ask why the default units are different: that is because `bitmap' can produce plots in formats that know about resolution, but png and jpeg do not. I am not sure I would have done it this way, but that's how Guido had done png and jpeg.> 2. Do png and jpeg usage inherit the paper size, width, and height set > by the postscript() or ps.options().None of those. png and jpeg have nothing to do with postscript and nothing to do with paper. They get the width and height from their width and height arguments (as documented).> 3. I see that png() and jpeg() have no "horizontal" option. Is that > because they are being saved in a file, and there is no need to > constrain them to fit in a piece of paper?They have nothing to do with paper (which can be held two ways round).> 4. Can you explain this? I did > >example(hist) > and a bunch of histograms flew by really fast. Then I did > > png(file="test.png") > > example(hist) > > dev.off() > I expected the file "test.png" to have just one figure, I was guessing > the last one that showed on the screen. But instead it was a figure with > 4 histograms, arrayed in a 2x2 matrix. What controlled that? png() has > no option like onefile=FALSE.It did have just one *plot*, but that's a multi-figure plot. Try with par(ask=TRUE) on screen. You got the first plot. When I did this I got an error message: Error in plot.new() : attempt to draw second page on pixmap device Did you miss that?> 5. I wish there was "maximum aspect-ratio preserving" adjustment for > size. If I'm looking at a graph on the screen, and I like it, except it > is too big, I'd like to specify a width and have R assume the > corresponding height. Otherwise, when I try to specify height and > width, R tries to stretch the objects being drawn and it looks like > hell. It is important to make this adjustment inside R, I think, in > order to keep the figure looking nice and to avoid scaling it in the > Gimp or something.There's code for that in dev.print. Unless you are copying the graph, there is no concept of aspect-ratio, which is device-dependent.> 6. The commands above suceeded with R-1.1.1 on RedHat 6.2, but with > R-1.1 on RedHat 6.1, I did the same things and the png and jpeg images > were corrupted/unviewable every time. Is this likely due to different > versions of X or ghostscript?Likely (or png/jpeg libraries). No other reports of problems, though. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._