The problem you have is that ranef()
stores the result of your analysis as a list, not data frame. You are trying to access this list as you would access data frame, that's why it doesn't work. The trick is to use double square bracket with dotplot
to access the list. Then you can use grid.arrange
to quickly combine your plots (or you can use @juba solution).
library(lme4)
fm3 <- lmer(strength ~ 1 + (1 | batch) + (1 | sample), Pastes)
d1 <- ranef(fm3, postVar=TRUE)
#double square bracket access the lists in d1
a <- dotplot(d1)[["batch"]]
b <- dotplot(d1)[["sample"]]
#grid.arrange combines your plots
library(gridExtra)
grid.arrange(a,b, nrow=1)