Skip to content
Prev 381491 / 398502 Next

R lattice stripplot add median line to data

Hi

I asked similar question few yeas ago (in different context) and besed on
answers I made custom function which adds line after the lattice graph is
plotted.

after your lattice plot just do

addLine(h=aggregate(df$Aboundance, list(df$Group), median)$x, once=T)

the function is defined as follows

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()
    }
  }

Cheers
Petr
how
use
variables are
horizontal
"brown3"))),
= meds[i],
4,
1,