[R] Printing out a graph using different graphics devices
Dimitri Liakhovitski
ld7631 at gmail.com
Mon Feb 16 18:14:06 CET 2009
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
More information about the R-help
mailing list