Re: [R] Howto fit normal curve into histogram using GGPLOT2

2009-09-02 Thread John Kane
gt; Subject: [R] Howto fit normal curve into histogram using GGPLOT2 > To: r-h...@stat.math.ethz.ch > Received: Wednesday, September 2, 2009, 10:36 AM > Currently, I am doing it this way. > > x <- mtcars$mpg > h<-hist(x, breaks=10, col="red", xlab="Miles Per >

Re: [R] Howto fit normal curve into histogram using GGPLOT2

2009-09-02 Thread ONKELINX, Thierry
answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey -Oorspronkelijk bericht- Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens Gundala Viswanath Verzonden: woensdag 2 september 2009 16:37 Aan: r-h...@stat.math.e

[R] Howto fit normal curve into histogram using GGPLOT2

2009-09-02 Thread Gundala Viswanath
Currently, I am doing it this way. x <- mtcars$mpg h<-hist(x, breaks=10, col="red", xlab="Miles Per Gallon", main="Histogram with Normal Curve") xfit<-seq(min(x),max(x),length=40) yfit<-dnorm(xfit,mean=mean(x),sd=sd(x)) yfit <- yfit*diff(h$mids[1:2])*length(x) lines(xfit, yfit, col="blue", lwd=