无法根据 ranef(lmerMod) 更改 lay-out 的 dotplot()(格子包)

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

我们正在尝试使用 dotplot 根据 lmer() 在 lme4 包中创建的 lmerMod object 的随机效应结构创建毛毛虫图。

情节本身创建得非常好,但是在尝试更改时 lay-out 发生错误。

没有 lay-out 指令的代码示例:

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')))

这创建了情节:

我们希望更改标题、轴标签和调色板。例如,要更改标题,通常的语法是

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

这会引发错误:

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

我们无法解决这个错误。无论我们在哪里看,这都适用于任何点图用法。任何人都可以解释一下吗?

P.S.: 我们在 ggplot() 上使用 dotplot() 是因为在将随机效应结构提取到数据框中时存在一些不规则性,如下所示:ggCaterpillar.由于以下原因,指定的函数抛出 NULL:

pv   <- attr(x, "postVar")

我们也试过其他方法提取variance/covariance矩阵来适配函数,摸索了一天感觉dotplot是比较简单的方法

你不能在这里不更改代码。查看S3方法的源代码 dotplot for ranef.mer class:

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

您不能设置标题诉状。如果您在某行中查看函数,它会明确地写成:

 mtit <- if (main) nx

其中 nx 是姓名 (x)(您的 ranef object)。

因此,如果您执行以下操作:

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

剧情标题会变。但这是一个黑客。最好在这里更改功能的代码并根据需要自定义它。

如果其他人看到这个,一个更简单的解决方案是先创建点图 object,然后使用 $ 运算符更改标题:

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