2

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.

Community
  • 1
  • 1
kneijenhuijs
  • 1,189
  • 1
  • 12
  • 21

2 Answers2

3

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.

agstudy
  • 119,832
  • 17
  • 199
  • 261
  • Wow, I never knew I could look at the source code like that. A whole new world. The function that is shown in the console, is the exact function of dotplot when combined with a ranef.mer object? That is really neat and should give me plenty of ways to customize it. Thanks! – kneijenhuijs Sep 30 '15 at 17:01
  • 1
    @kneijenhuijs yes the function is what you see in the console.You can copy and paste it and do the customization. The function name is `dotplot.ranef.mer`(You should keep this name) – agstudy Oct 01 '15 at 00:06
1

If anyone else sees this, a simpler solution would be to create the dotplot object first, and then change the title using the $ operator:

dp <- dotplot(randoms, scales = list(x = list(relation = 'free')))
dp$VSVnr$main <- "Title"
Pepper
  • 31
  • 5