[R] Re : Re : Adding mean line to a lattice density plot
Petr PIKAL
petr.pikal at precheza.cz
Thu Mar 8 15:53:54 CET 2012
Hi
You can use this function to add arbitrary line to already plotted lattice
graph.
addLine<- function(a=NULL, b=NULL, v = NULL, h = NULL, ..., once=F) {
tcL <- trellis.currentLayout()
k<-0
for(i in 1:nrow(tcL))
for(j in 1:ncol(tcL))
if (tcL[i,j] > 0) {
k<-k+1
trellis.focus("panel", j, i, highlight = FALSE)
if (once) panel.abline(a=a[k], b=b[k], v=v[k], h=h[k], ...) else
panel.abline(a=a, b=b, v=v, h=h, ...)
trellis.unfocus()
}
}
the usage is similar to abline in base graphics.
addLine(h=some number)
Regards
Petr
>
> Hi Kimmo,
>
> Unfortunately, I can't visualize the attachment. Could you provide an
> example I can reproduce?
>
> Regards,
> Pascal
>
>
>
> ----- Mail original -----
> De : K. Elo <maillists at nic.fi>
> À : r-help at r-project.org
> Cc :
> Envoyé le : Jeudi 8 mars 2012 22h38
> Objet : Re: [R] Re : Adding mean line to a lattice density plot
>
> 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
>
> ______________________________________________
> 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.
>
>
> ______________________________________________
> 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