[R] truehist and density plots
Peter Flom
peterflomconsulting at mindspring.com
Tue Apr 28 15:43:03 CEST 2009
carol white <wht_crl at yahoo.com> wrote
>Consider a vector of 100 elements (attached files). then,
>
>truehist(b)
>lines(density(b[20:50]))
>
>How is it possible to have density plots of all subsets like b[20:50] within histogram (without exceeding the max of historgram on y axis)?
>
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
More information about the R-help
mailing list