[R] draw a function over a histogram

Rubén Roa-Ureta rroa at udec.cl
Fri Aug 22 16:55:16 CEST 2008


Daniela Garavaglia wrote:
> Sorry, I have some troubles with the graph device.
>
> How can I draw a function over a histogram?
>
> Thank's so much.
>   
Daniela,
What function?
Here is one example using density() and using dnorm()
x <- rnorm(1000,2,2)
hist(x,prob=TRUE)
lines(density(x,na.rm=TRUE),col="red")
library(MASS)
y <- fitdistr(x,"normal")
curve(dnorm(x,mean=y$estimate[1],sd=y$estimate[2]),add=TRUE)

HTH
R.

> 	[[alternative HTML version deleted]] <--- What about this??
>
>



More information about the R-help mailing list