[R] how to plot the histogram and the curve in the same graph
Greg Snow
Greg.Snow at imail.org
Tue Oct 21 20:00:13 CEST 2008
It is not clear what curve you want to plot, but this code may help get you started (the final plot will probably need the x and y limits expanded and maybe other options changed):
x <- rnorm(100, rep( c(100,105), c(75,25)), 2 )
hist(x, probability=TRUE)
lines( density(x), col='green' )
curve( dnorm(x, mean=mean(x), sd=sd(x)), col='blue', add=TRUE )
see the help for hist, lines, and curve for details.
Hope this helps,
--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of leo_wa
> Sent: Monday, October 20, 2008 8:47 PM
> To: r-help at r-project.org
> Subject: [R] how to plot the histogram and the curve in the same graph
>
>
> 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.
> --
> View this message in context: http://www.nabble.com/how-to-plot-the-
> histogram-and-the-curve-in--the-same-graph-tp20082506p20082506.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at 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.
More information about the R-help
mailing list