[R] lines density

Duncan Murdoch murdoch.duncan at gmail.com
Sat Nov 17 17:26:16 CET 2012


On 12-11-17 5:38 AM, bgnumis wrote:
> Hi all,
>
> I attach a picture, with my output plot.
>
> I put this command to obtain it:
>
> hist(MCT[,2],probability=TRUE,xlab=" ",ylab="Max",main="M distribution")
> lines(density(MCT[,2]), lwd = 2)
>
> The problem is that when I extract the "bell" is too high? And the higher
> part doesn´t appear in the plot. There is some trick to adjust the line on
> the plotted area?
>

You need to set ylim in your call to hist().  You can do it by trial and 
error, or compute the numbers first via

h <- hist(MCT[,2], plot=FALSE)

and set

ylim <- range(c(0, h$density, density(MCT[,2])$y))

before you plot:

hist(MCT[,2], probability=TRUE, ylim=ylim, xlab=" ", ylab="Max", main="M 
distribution")
lines(density(MCT[,2]), lwd = 2)

Duncan Murdoch




More information about the R-help mailing list