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

K. Elo maillists at nic.fi
Thu Mar 8 14:38:56 CET 2012


Hi,

thank you, Pascal, for your quick reply. Unfortunately your suggestion 
is not working. Please have a look on the attachment, I have added 
manually the mean lines I am trying to plot. The problem with 'abilne' 
seems to be that the argument 'v' is relative to the graph area, not the 
x-axis scale. Thus, plottingat v='mean' won't work...

Any suggestions?

Kind regards,
Kimmo

08.03.2012 09:49, Pascal Oettli wrote:
> 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


More information about the R-help mailing list