kneijenhuijs kneijenhuijs - 1 year ago 99
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

object created by
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:


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
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 Source

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


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" 

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download