Skip to content
Prev 178663 / 398506 Next

truehist and density plots

carol white <wht_crl at yahoo.com> wrote
I didn't open your attached file  but 

b <- rnorm(100)
library(MASS)
truehist(b)
lines(density(b[20:50]))


works fine

if some of your density plots line go too high, then you can first find the maximum and then use that in the truehist function, which has ymax.

There's probably some elegant way to find the max, but I *THINK* this is right:
den1 <- density(b[20:50])
max1 <- max(den1[[2]])

then, if you have a lot of densities, you could get
maxim <- max(max1, max2) or some such

HTH

Peter


Peter L. Flom, PhD
Statistical Consultant
www DOT peterflomconsulting DOT com