[R] Concat Multiple Plots into one PNG figure
Gundala Viswanath
gundalav at gmail.com
Tue Jun 10 09:28:19 CEST 2008
Dear experts,
I tried to put the two plots into one final PNG figure
with the following script.
However instead of giving 2 plots in one figure,
it only gives the the last plot in one figure.
What's wrong with my script below?
__BEGIN__
in_fname <- paste("mydata.txt.",sep="")
out_fname <- paste("finalplot.png",sep="")
dat <- read.table(in_fname, comment.char = "!" , na.strings = "null");
dat.pca <- prcomp(dat[,1:ncol(dat)], retx=TRUE, scores=TRUE)
trellis.device("png", color=TRUE)
png(out_fname)
# End figure expected to be 1 row 2 columns
par(mfrow = c(1,2))
# Two plots which I want to put into one PNG figure
xyplot(dat.pca$x[,1] ~ dat.pca$x[,2], xlab="First Component",
ylab="Second Component")
xyplot(dat.pca$x[,2] ~ dat.pca$x[,3], xlab="Second Component",
ylab="Third Component")
dev.off()
__END__
--
Gundala Viswanath
More information about the R-help
mailing list