. I am looking for a histogram or box plot with the adding normal distribution curve I think that must be possible, but I am not able to find out how to do. Regards Knut
Hi answered hundered times.> Dear R people: > > I would like to superimpose a normal curve on a histogram.x<-rnorm(150) h<-hist(x,breaks=15) xhist<-c(min(h$breaks),h$breaks) yhist<-c(0,h$density,0) xfit<-seq(min(x),max(x),length=40) yfit<-dnorm(xfit,mean=mean(x),sd=sd(x)) plot(xhist,yhist,type="s",ylim=c(0,max(yhist,yfit))) lines(xfit,yfit) Bill above is e.g. Bill Simpson's answer from 2001. Found from R-site search ***histogram density normal***. HTH Petr On 25 Sep 2005 at 14:34, Knut Krueger wrote:> . > I am looking for a histogram or box plot with the adding normal > distribution curve I think that must be possible, but I am not able > to find out how to do. > > > > Regards Knut > > ______________________________________________ > 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.htmlPetr Pikal petr.pikal at precheza.cz
Le 25.09.2005 14:34, Knut Krueger a ??crit :>. >I am looking for a histogram or box plot with the adding normal >distribution curve >I think that must be possible, but I am not able to find out how to do. > > > >Regards Knut > >Hi Knut, There are a lot of ways to do that, let x be your data (assume x ~ N(mu=2,sd=.4)) R> x <- rnorm(200, mean=2, sd=.4) ** With the traditionnal graphics system, do : R> hist(x, prob=T) R> curve(dnorm, col=2, mean=mean(x), sd=sd(x)) ** With lattice : R> histogram(~x, panel = function(x,...){ panel.histogram(x,...) panel.mathdensity(dmath = dnorm, col = "red", args = list(mean=mean(x),sd=sd(x))) }, type="density") Then, have a look at : http://addictedtor.free.fr/graphiques/search.php?q=hist And also have a nice day.... Romain -- visit the R Graph Gallery : http://addictedtor.free.fr/graphiques ~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~ ~~~~~~ Romain FRANCOIS - http://addictedtor.free.fr ~~~~~~ ~~~~ Etudiant ISUP - CS3 - Industrie et Services ~~~~ ~~ http://www.isup.cicrp.jussieu.fr/ ~~ ~~~~ Stagiaire INRIA Futurs - Equipe SELECT ~~~~ ~~~~~~ http://www.inria.fr/recherche/equipes/select.fr.html ~~~~~~ ~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~
Knut Krueger wrote:>. >I am looking for a histogram or box plot with the adding normal >distribution curve >I think that must be possible, but I am not able to find out how to do. > > > >Regards Knut > >______________________________________________ >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 >*There are a lot of answers to add a histogram. Here is a simple way to add a tiny boxplot to a plot / histogram x<-rexp(100) hist(x) boxplot(x,axes=F,add=T,horizontal=T, at=par()$usr[3]+diff(par()$usr[3:4])*.017, boxwex=0.02*diff(par()$usr[3:4]),pch=8) Peter Wolf *
> > >Knut Krueger wrote: > > > > > >>I am looking for a histogram or box plot with the adding normal > >>distribution curve > >>I think that must be possible, but I am not able to find > out how to do. > >>Since there are various solutions, here is mine: hist(rnorm(10000), freq=FALSE) xvals <- seq(-5,5,length=100) lines(x=xvals, y=dnorm(xvals)) Is this what you are looking for? Best, Roland +++++ This mail has been sent through the MPI for Demographic Rese...{{dropped}}