[R] How to plot two graphs on one single plot?
Matthew Keller
mckellercran at gmail.com
Fri Feb 23 16:42:05 CET 2007
Hi Yun,
If you're asking how to place new graphic material on the same plot
(e.g., several lines/points/etc in a single x-y region), this is
covered in the Intro to R manual. E.g., you can do:
plot(x1, y1, type='p', xlim=range(x1,x2), ylim=range(y1, y2),
xlab='x', ylab='y')
points(x2, y2, col="red")
see ?lines ?points ?text ?abline Also, see the "new" option in par
Best,
Matt
On 2/23/07, Yun Zhang <yunzhang at princeton.edu> wrote:
> Hi,
>
> I am trying to plot two distribution graph on one plot. But I dont know
> how. I set them to the same x, y limit, even same x, y labels.
>
> Code:
> x1=rnorm(25, mean=0, sd=1)
> y1=dnorm(x1, mean=0, sd=1)
>
> x2=rnorm(25, mean=0, sd=1)
> y2=dnorm(x2, mean=0, sd=1)
> plot(x1, y1, type='p', xlim=range(x1,x2), ylim=range(y1, y2), xlab='x',
> ylab='y')
> plot(x2, y2, type='p', col="red", xlab='x', ylab='y')
>
> They just dont show up in one plot.
>
> Any hint will be very helpful.
>
> Thanks,
> Yun
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>
--
Matthew C Keller
Postdoctoral Fellow
Virginia Institute for Psychiatric and Behavioral Genetics
More information about the R-help
mailing list