kneijenhuijs kneijenhuijs - 2 months ago 9
R Question

Can not change lay-out of dotplot() (lattice package) based on ranef(lmerMod)

We're trying to use dotplot to create a caterpillarplot based on the random effect structure of a

lmerMod
object created by
lmer()
in the lme4 package.

The plot itself is created perfectly fine, but when trying to change the lay-out errors occur.

Sample of code without lay-out instructions:

all_bv_C <- lmer(RQ_EvT_A ~ SD_Lft_M_Cat4 + SD_Opl_M_Cat3 + OV_Gez_M_4 + (1|VSVnr), data=BV2, REML=TRUE)

random <- ranef(all_bv_C, condVar = TRUE)

dotplot(randoms, scales = list(x = list(relation = 'free')))


This creates the plot:

dotplot

We wish to change the title, axis labels and the color palette. For example, to change the title, the usual syntax would be

dotplot(randoms, scales = list(x = list(relation = 'free')), main="Title")


This throws the error:


Error in if (main) nx : argument is not interpretable as logical


We've been unable to get around this error. Everywhere we looked, this should work for any dotplot usage. Can anyone shed some light?

P.S.: We're using
dotplot()
over
ggplot()
due to some irregularities in extracting the random effect structure into a data frame as would be suggested here: ggCaterpillar. The function specified throws a NULL due to:

pv <- attr(x, "postVar")


We've also tried other routes for extracting the variance/covariance matrix to adapt the function, but felt that dotplot was the easier route after fumbling for a day.

Answer

You can not here without changing the code. Looking at the source code of the S3 method dotplot for ranef.mer class:

getS3method("dotplot","ranef.mer")

You can not set the titles suing arguments. If you look in the function in some line it is written explicitly:

 mtit <- if (main) nx

where nx is the names(x)( your ranef object).

So if you do somthing like :

names(randoms) <- "Title" 
dotplot(randoms)

the plot title will change. But this is a hack. Better here to change the code of the function and customize it as you like.