[OGRUG] Putting two figures together in R

Robert Biddle robtbiddle at gmail.com
Tue Jul 20 15:58:18 CEST 2010

I'm not 100% sure I know what you want, but if it's just to have
two plots in the same image side by side, I do this all the time using 
par and mfrow.
A simple example would go like this:

 > par(mfrow=c(1,2))
 > hist(runif(100))
 > boxplot(runif(100))
 > par(mfrow=c(1,1))

That gives an image with a histogram on the left and a boxplot on the right.
You can vary the mfrow numbers as you wish to have them in a row, a 
column, or a grid.
The c(1,1) setting at the end is just to change back to a single plot.

Anyway, when it looks right, then you can just save the window to a file.
For data and graphs I tinker with a lot, I normally embed this kind of 
thing within a call to pdf or png to
both display the images and save them to a file.

Anyway, I hope this helps.
Robert Biddle

On 10-07-19 6:28 PM, Young Song wrote:
> Hello,
>    I have two scripts that are used to generate heatmap and bar graph
> *A. Heatmap script:*
> library(RColorBrewer)
> library(gplots)
> par(mfrow=c(2,1))
> Totaltax<-read.table("heatmap_data.txt",header=TRUE)
> Totaltax_log<-log(Totaltax+1)
> Totaltax_mat<-data.matrix(Totaltax_log)
> Totaltax_column<-t(Totaltax_mat)
> cdendro<-as.dendrogram(hclust(dist(Totaltax_column, 
> method="manhattan")),method="complete")
> heatmap.2(Totaltax_mat, Colv=cdendro, distfun=dist, key=TRUE, 
> keysize=1, trace="none", margins=c(5,13), col=brewer.pal(9,"BuPu"))
> *B. Bar graph script:*
> histo <- read.table("histo_data.txt", header=T)
> barplot(histo$Value)
> Usually, I would run each script separately, and put the two resulting 
> diagrams together using Adobe Illustrator.  I was wondering if there 
> is a way to put these two diagrams together in R, instead of going 
> through the manual procedures.  I am currently using R version 2.11.1 
> on Mac OS X 10.6.  The actual data used to generate the diagrams are 
> attached in this message.  Thank you very much in advance.
>  Sincerely,
>    Young
> -- 
> Young C. Song
> Masters Student
> University of British Columbia Graduate Program in Bioinformatics
> Vancouver, BC V6T 1Z4, Canada
> _______________________________________________
> R-UG-Ottawa mailing list
> R-UG-Ottawa at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-ug-ottawa

More information about the R-UG-Ottawa mailing list