[R] Re : Adding mean line to a lattice density plot

Pascal Oettli kridox at ymail.com
Thu Mar 8 08:49:58 CET 2012


Hi Kimmo,

You can try to use the "layer" function from "latticeExtra" library:

densityplot(~PV1CIV, groups=SGENDER, data=ISGFINC2,
  lwd=2, col=1, lty=c(1,2), pch=c("+","o"),
  key=list(text=list(lab=levels(ISGFINC2$SGENDER), col=1),
  space="bottom", columns=2, border=T, lines=T, lwd=2,
  lty=c(1,2), col=1), ref=T, plot.points=F) + layer(panel.abline(v=mean(PV1CIV[ SGENDER==1 ])))

Regards,
Pascal




----- Mail original -----
De : K. Elo <maillists at nic.fi>
À : r-help at r-project.org
Cc : 
Envoyé le : Jeudi 8 mars 2012 16h35
Objet : [R] Adding mean line to a lattice density plot

Hi!

I have used the following command:

densityplot(~PV1CIV, groups=SGENDER, data=ISGFINC2,
  lwd=2, col=1, lty=c(1,2), pch=c("+","o"),
  key=list(text=list(lab=levels(ISGFINC2$SGENDER), col=1),
  space="bottom", columns=2, border=T, lines=T, lwd=2,
  lty=c(1,2), col=1), ref=T, plot.points=F)

to produce a lattice density plot presenting the distribution of achievment points grouped by the gender of the respondents.

Now, in order to clarify the difference between boys and girls, I would like to add two vertical lines: one for the mean of boys, the other for the mean of girls. How could I do this (I have tried to use the function 'panel.abline', but could not figure out how to define the correct x-axis point (using 'v=mean(PV1CIV[ SGENDER==1 ])' as a parameter is not working...).

Thanks in advance,
Kimmo

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




More information about the R-help mailing list