[R] getting multiple plots on a single plot

Vihan Pandey vihanpandey at gmail.com
Thu Mar 22 20:18:35 CET 2012


Hi all,

I have the following R script :


#!/usr/bin/Rscript

out_file = "hybrid.pdf"
pdf(out_file, height=8.5, width=11)

myvalues_1M <- read.csv("hybrid_sims_1M.csv",head=TRUE,sep=",")
plot(myvalues_1M$num_sims_per_thread,myvalues_1M$time_per_sim,xlab="Number
of Simulations per Thread",ylab="Time per 1 million Simulations(in
milliseconds)",col="red",main="For 1 million simulations")
lines(myvalues_1M$num_sims_per_thread,myvalues_1M$time_per_sim,col="red")

myvalues_5M <- read.csv("hybrid_sims_5M.csv",head=TRUE,sep=",")
plot(myvalues_5M$num_sims_per_thread,myvalues_5M$time_per_sim,xlab="Number
of Simulations per Thread",ylab="Time per 1 million Simulations(in
milliseconds)",col="blue",main="For 5 million simulations")
lines(myvalues_5M$num_sims_per_thread,myvalues_5M$time_per_sim,col="blue")

myvalues_10M <- read.csv("hybrid_sims_10M.csv",head=TRUE,sep=",")
plot(myvalues_10M$num_sims_per_thread,myvalues_10M$time_per_sim,xlab="Number
of Simulations per Thread",ylab="Time per 1 million Simulations(in
milliseconds)",col="green",main="For 10 million simulations")
lines(myvalues_10M$num_sims_per_thread,myvalues_10M$time_per_sim,col="green")

dev.off()

print(paste("Plot was saved in:", getwd()))



This generates a 3 page pdf file with a plot on each page. They look like this :

http://s17.postimage.org/ud9ej1cnj/alpha1.png
http://s13.postimage.org/7q3snqsrr/alpha2.png
http://s14.postimage.org/sf374f12p/alpha3.png

I want to plot all the 3 in one graph, in one page with the respective
colours - red, blue, and green. Any ideas on how?

Thanks,

- vihan



More information about the R-help mailing list