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
Don't use plot three times -- it opens a new page when pdf() is your current device. Do the first with plot -- then use lines() online from there to the end. Michael On Thu, Mar 22, 2012 at 3:18 PM, Vihan Pandey <vihanpandey at gmail.com> wrote:> 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 > > ______________________________________________ > 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.
vihan, you jsut need to add the following statement in the subsequent plot commands: add = TRUE so that your second and later plot commands look similar to: 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", add = TRUE) HTH Chris On 03/22/2012 03:18 PM, Vihan Pandey wrote:> 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 > > ______________________________________________ > 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. >
On Mar 22, 2012, at 3:18 PM, Vihan Pandey wrote:> Hi all, > > I have the following R script : > > > #!/usr/bin/Rscript > > out_file = "hybrid.pdf" > pdf(out_file, height=8.5, width=11)At this point (assuming that you want three separate plots on the same page which is unclear but you do use different titles and ylabs, so I think this is implied) you would either be using layout() ?layout .... or par() with arguments mfrow, mfcol, or mfg. ?par> > 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")If on the other hand you want one plot frame with overlaid point/lines/ etc, then you should be determining your x and y limits before any plots and putting in the same limits for each plot Adding all your labels on the first plot and using: par(new=TRUE) # which seems completely backward to me. # I say again ... ? par> > 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 > > ______________________________________________ > 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.David Winsemius, MD West Hartford, CT
On 22 March 2012 20:54, Chris Snook <snook_c at bellsouth.net> wrote:> vihan, > > you jsut need to add the following statement in the subsequent plot > commands: > > add = TRUE > > so that your second and later plot commands look similar to: > > 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", add = TRUE)Thanks, but that still does keeps it on different pages and generates warnings : Warning messages: 1: In plot.window(...) : "add" is not a graphical parameter 2: In plot.xy(xy, type, ...) : "add" is not a graphical parameter 3: In axis(side = side, at = at, labels = labels, ...) : "add" is not a graphical parameter 4: In axis(side = side, at = at, labels = labels, ...) : "add" is not a graphical parameter 5: In box(...) : "add" is not a graphical parameter 6: In title(...) : "add" is not a graphical parameter Cheers! - vihan> > HTH > > Chris > On 03/22/2012 03:18 PM, Vihan Pandey wrote: >> 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 >> >> ______________________________________________ >> 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. >> > > ______________________________________________ > 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.