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" <[EMAIL PROTECTED]> >To: <[email protected]> >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 > >[EMAIL PROTECTED] > > > > > > [[alternative HTML version deleted]] > >______________________________________________ >[email protected] mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide! >http://www.R-project.org/posting-guide.html ______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
