[R] newbie graphics question: Two density plots in same frame ?
Francisco J. Zagmutt
gerifalte28 at hotmail.com
Thu Nov 3 18:15:46 CET 2005
To plot two Kernel densities you can use matplot:
x1<-density(rnorm(100))
x2<-density(rnorm(100))
matplot(cbind(x1$y,x2$y), type="l")
Or if both distributions are really very similar and you don't have to
adjust the axes you can simply use
plot(x1)
lines(x2, col="red")
Finally if you want to have two histograms in the same picture (I would not
recomend it tough since the distributions are similar so the overlapping
will make it very messy) you can use the argument "add" within hist
hist(rnorm(100), col="red")
hist(rnorm(100), col="blue", add=T)
I hope this helps
Francisco
>From: "Alpert, William" <William.Alpert at barrons.com>
>To: <r-help at stat.math.ethz.ch>
>Subject: [R] newbie graphics question: Two density plots in same frame ?
>Date: Thu, 3 Nov 2005 11:45:21 -0500
>
>I swear I've scoured the help files and several texts before posting
>what feels like a dumb newbie question.
>
>How can I draw two kernel density plots in the same frame ? I have
>similar variables in two separate data frames, and I would like to show
>their two histograms/densities in a single picture. Same units, scale,
>range for both, so I'm simply trying to draw one and then add the other
>to the picture. Nothin' fancy.
>
>
>Bill Alpert
>
>Sr. Editor
>
>Barron's
>
>212.416.2742
>
>william.alpert at barrons.com
>
>
>
>
>
> [[alternative HTML version deleted]]
>
>______________________________________________
>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
More information about the R-help
mailing list