[R] Creating a simple line graph

Liviu Andronic landronimirc at gmail.com
Thu Aug 27 18:46:28 CEST 2009


Hello

On 8/27/09, Josh Roll <j_r_36 at hotmail.com> wrote:
>     I am having trouble getting both graphs on the same page.  Its
> separating them, especially when i write them to a pdf.  I need visual
> comparison capabilities.  Do i need to include the two data sets in the same
> "plot" to make this happen.  Thanks
>
http://www.statmethods.net/advgraphs/layout.html
http://wiki.r-project.org/rwiki/doku.php?id=tips:graphics-base:overlapping_plots

Perhaps this:
Sz= c("h1","h2","h3","h4")
 Pred=c(34790.0 ,47559.8, 21197.8, 28198.6)
 Obs=c(34740 ,48615 ,20420, 26840)
 plot(Pred, t="l", ylim=c(20000,50000))
 text(Pred, Sz, cex=0.6, pos=4, col="red")
 par(new=TRUE)
 plot(Obs, t="l", ylim=c(20000,50000))
 text(Obs, Sz, cex=0.6, pos=4, col="blue")

Alternatively you can use lines(), but always pay attention that both
graphs be constructed with teh same x and y limits.
Liviu




More information about the R-help mailing list