Re: [R] two density curves in one plot?

From: Dimitris Rizopoulos <dimitris.rizopoulos_at_med.kuleuven.be>
Date: Wed 23 Aug 2006 - 21:25:58 EST

try this:

x1 <- rnorm(1000)
x2 <- rnorm(1000)

d1 <- density(x1)
d2 <- density(x2)
plot(range(d1$x, d2$x), range(d1$y, d2$y), type = "n",

     xlab = "x", ylab = "Density")
lines(d1, col = "red")
lines(d2, col = "blue")

I hope it helps.

Best,
Dimitris



Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium

Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
     http://www.student.kuleuven.be/~m0390867/dimitris.htm


> Hello,
>
> I was wondering if I can plot two curves I get from "density(data)"
> into
> one plot. I want to compare both.
> With the following commad, I just get one curve plotted:
>
> plot( density(mydata) )
>
> Sorry for this stupid question but I could not find a solution until
> now...
>
> Antje
>
> ______________________________________________
> R-help@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.
>

Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm



R-help@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. Received on Wed Aug 23 22:40:48 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 24 Aug 2006 - 00:20:54 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.