[R] hist(x, ...) with normal distribution curve

Petr Pikal petr.pikal at precheza.cz
Mon Sep 26 14:52:36 CEST 2005


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.html

Petr Pikal
petr.pikal at precheza.cz




More information about the R-help mailing list