leo_wa wrote:
i want to plot the histogram and the curve in the same graph.if i have a set
of data ,i plot the histogram and also want to see what distribution it
was.So i want to plot the curve to know what distribution it like.
To draw the curve and the distribution you should have an idea about the distribution. You cann't just draw the histogram and expect R to make a curve of the best distribution to fit that histogram.
But you can plot a curve of a kernel density.

x <- rnorm(1000,5,3)
library(MASS)
(x.normfit <- fitdistr(x,"normal"))
hist(x,prob=TRUE)
lines(density(x,na.rm=TRUE),col="red") # kernel density
curve(dnorm(x,mean= x.normfit$estimate[1],sd= x.normfit$estimate[2]),col="blue",add=TRUE) #maximum likelihood estimate

Rubén

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to