[R] Histogram of data with categorical varialbe
Romain Francois
rfrancois at mango-solutions.com
Fri Sep 15 17:19:42 CEST 2006
Alexandre Depire wrote:
> Hello,
> I have the following data:
> Km Sex
> 250 1
> 300 2
> 290 2
> 600 1
> 450 2
> 650 1
> .........
>
> I would like to obtain one histogram where the data (or the part) of each
> sex is visible, it is like cumulative histogram or spinogram.
> To be more comprehensible, i would like to know if the following graph is
> obtainable easily in R. It is the first graph on page 5 in the following
> document http://jasp.ism.ac.jp/~nakanoj/workshop04/TalkII.pdf
>
Something like :
d <- data.frame( x = rnorm(100), sex = sample(c(1,2), replace=TRUE,
size=100))
out <- hist(d$x, col="gray")
hist(d$x[d$sex==2], col="red", add=T, breaks=out$breaks)
legend("topleft", c("male","female") , fill=c("gray","red"))
box()
Cheers,
Romain
--
*mangosolutions*
/data analysis that delivers/
Tel +44 1249 467 467
Fax +44 1249 467 468
More information about the R-help
mailing list