3
$\begingroup$

I guess this is a basic question but I've been looking after a solution for a long time without result.

I'm using lme4 package and I use this code :

library(lme4)
plot(confint(lmList(Reaction ~ Days | Subject, sleepstudy), pooled = FALSE),
     order = 1)

to plot confidence intervals for individual coefficients of intercept and slope:

enter image description here

I just want to add a vertical line (v=0) in both panels to be able to better show which CI contains 0. I've tried to use panel.abline but without success.

plot(confint(lmList(Reaction ~ Days | Subject, sleepstudy), pooled = FALSE),
       order = 1,
       panel=function(...){
       panel.plot(...)
       panel.abline(v=0, col="grey")
})
$\endgroup$
7
$\begingroup$

Since the plot of confint(lmList) is a trellis object, additions to the plot can be accomplished via the latticeExtra package, but you have to assign the plot to an object first. The vertical line is then added to the plot object with + layer(panel.refline...).

From the lme4 example:

library(lme4)
library(lattice)
library(latticeExtra)

Rxplot <- plot(confint(lmList(Reaction ~ Days | Subject, sleepstudy), pooled = FALSE))
Rxplot + layer(panel.refline(v = v, col.line = "grey"), data = list(v = 0))
$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.