[R] Concat Multiple Plots into one PNG figure

Greg Snow Greg.Snow at imail.org
Tue Jun 10 18:21:32 CEST 2008


Look at ?print.trellis in the lattice package (specifically the split and more argumnets).

--
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 Gundala Viswanath
> Sent: Tuesday, June 10, 2008 9:27 AM
> To: r-help at stat.math.ethz.ch
> Subject: [R] Concat Multiple Plots into one PNG figure
>
> 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
>
>
>
> --
> Gundala Viswanath
>
> ______________________________________________
> 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