Re: [R] How to overlap two density plots?

From: Jared O'Connell <jared.oconnell_at_gmail.com>
Date: Sat, 26 Apr 2008 13:51:14 +0200

My apologies, the previous replies did not show up for me.

On Sat, Apr 26, 2008 at 1:49 PM, Jared O'Connell <jared.oconnell_at_gmail.com> wrote:
> Very nšively, you could do something like this,
>
> plot(density(A))
> lines(density(B),col=2)
>
> , and tinker your xlim and ylim as suitable. The Cairo library gives
> a pretty example,
>
> data(iris)
> attach(iris)
> plot(Petal.Length, rep(-0.03,length(Species)), xlim=c(1,7),
> ylim=c(0,1.7), xlab="Petal.Length", ylab="Density",
> pch=21, cex=1.5, col="#00000001", main = "Iris (yet again)",
> bg=c("#ff000020","#00ff0020","#0000ff20")[unclass(Species)])
> for (i in 1:3) polygon(density(Petal.Length[unclass(Species)==i],bw=0.2),col=c("#ff000040","#00ff0040","#0000ff40")[i])
>



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. Received on Sat 26 Apr 2008 - 11:53:46 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 26 Apr 2008 - 14:30:31 GMT.

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

list of date sections of archive