Reputation: 3805
library("lme4")
data(sleepstudy)
fit1 <- lmer(Reaction ~ Days + (1|Subject), sleepstudy)
To visualise the random effect,
library(sjPlot)
plot_model(fit1,type = "re",facet.grid = FALSE)
In my orginal data, I have three random groups. However, if I want to plot the random effects, they all come in three separate plots. How can I put them in all single plot in 1 X 3 panel or 3 X 1 panel.
Upvotes: 2
Views: 3949
Reputation: 72813
You could use gridExtra::grid.arrange()
fit1 <- lmer(Reaction ~ (1|Days) + (1|Subject), sleepstudy)
library(sjPlot)
p <- plot_model(fit1, type = "re", facet.grid=FALSE)
library(gridExtra)
grid.arrange(p[[1]], p[[2]])
Produces:
You also could consider lattice::qqmath()
.
library(lattice)
p2 <- qqmath(ranef(fit1, condVar=TRUE))
grid.arrange(p2[[1]], p2[[2]])
Produces:
Note: To specify the columns use the ncol
option. Compare e.g. grid.arrange(p2[[1]], p2[[2]], ncol=2)
vs. grid.arrange(p2[[1]], p2[[2]], ncol=1)
.
Upvotes: 4