Hi,

Instead of hist you can use functions histogram() or densityplot() in
lattice package:

require(lattice)

histogram(
            ~ length | factor(sex), data=dene
            )

densityplot(
            ~ length, data=dene,
            groups=factor(sex),
            auto.key = list(space = "bottom")
          )

Regards,
Carlos Ortega
www.qualityexcellence.es


On Mon, Jul 18, 2011 at 3:50 PM, Jacob Kasper <jacobkas...@gmail.com> wrote:

> I have a data set that looks like this:
> dene <- data.frame(length =
> c(35,32,33,34,41,40,46,35,41,40,45,36,38,37,39,40,42,42,42,43,44),
> sex=c(1,1,1,1,2,2,2,1,2,2,2,1,2,2,2,2,2,2,2,2,2))
>
> I would like to plot the density (frequency of occurrence) of each length
> class but I want to have different colors for sex. I used the following:
> library(sm)
> sex.f<-factor(as.factor(dene$sex),levels=c(1,2),
> labels=c("Males","Females"))
> sm.density.compare(dene$length, dene$sex)
> yet I want the sum of the areas under the two curves to be equal to 1, not
> the sum of the area under each curve to be equal to 1.
>
> I can plot the frequency using hist, but then I do not get the two colors
> indicating the difference in sex.
>
>
> hist(dene$length, freq=F, breaks=11)
>
> any thoughts on how to approach this would be appreciated.
>
> Thank you
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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.
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to