[R] Printing out a graph using different graphics devices

Greg Snow Greg.Snow at imail.org
Mon Feb 16 21:56:29 CET 2009


You might want to look at the dev.copy function.  I just tried with your example and the postscript device, used the print(plot) command with the postscript device open, then switched to the windows graphics device and did dev.copy then closed the postscript file, the result had 2 pages, the first like you described looked different from the screen, the 2nd (from dev.copy) had the same colors and general appearance (I did not compare super closely) as the plot on the screen.

Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Dimitri Liakhovitski
> Sent: Monday, February 16, 2009 10:14 AM
> To: R-Help List
> Subject: [R] Printing out a graph using different graphics devices
> 
> Hello, everyone!
> The code below allows me to produce the graph I want (I know - the
> colors are strange, but it's just for the sake of an example).
> After you run the plot<- part and then do print(plot) - that's what I
> want.
> However, when I run the bits of code below (with graphics devices) -
> what they print is different from the original plot. In .png, .emf,
> and .tiff - my dots change their shape and my lines (I think) become
> thinner. And in .ps format - the dots stay what they are supposed to
> be but they change their color.
> Could you please explain to me what the reasons are for those changes?
> Also - should I specify my chart characteristics differently depending
> on the device I'll be using?
> Thank you very much!
> Dimitri
> 
> library(lattice)
> d=data.frame(xx=c(2.2,2.1,3.3),yy=c(0.1,0.2,0.3),zz=c(2.5,2.0,1.8))
> d[[2]]<-as.factor(as.numeric((d[[2]])))
> 
> trellis.par.set(superpose.line = list(col=c("green","red"), lwd = 2),
>                superpose.symbol = list(col=c("yellow","blue"),cex =
> 1.3, pch = 20),
>                reference.line = list(col = "gray", lty ="dotted"))
> 
> plot<-dotplot(c(d[[1]],d[[3]])~rep(d[[2]],2),
>        groups=rep(c("Group 1","Group 2"), each=nrow(d)),
>        main=list("Chart Title",cex=1),
> 
>        type="b",
>        auto.key = list(space = "top", points = TRUE, lines = TRUE),
> 
>        xlab=list("Title for X",cex=.9,font=2),
>        ylab=list("Title for Y",cex=.9,font=2),
> 
>        panel = function(y,x,...) {
>            panel.grid(h = -1, v = -1)
>            panel.xyplot(x, y, ...)
> 
>            ltext(x, y, labels=round(y,3),
>                  cex=.8,col="black",font=2,
>                  adj=c(-0.2,1))
> 
>        })
> print(plot)
> 
> win.metafile(file="test.emf")
> print(plot)
> dev.off()
> 
> postscript(file="test.ps")
> print(plot)
> dev.off()
> 
> png(file="test.png")
> print(plot)
> dev.off()
> 
> tiff(file="test.tiff")
> print(plot)
> dev.off()
> 
> --
> Dimitri Liakhovitski
> MarketTools, Inc.
> Dimitri.Liakhovitski at markettools.com
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list