I'm trying to make a boxplot to visualize this regression model
library(lme4)
lmer(dv1 ~ intervention + (1|id/area),
data=data,
REML=T)
In this experiment, the control and treatment intervention are both applied to a subject within discrete areas.
Here's the data I'm using
data <- data.frame("id" = 1:2,
"intervention" = c(rep("a",27),rep("b", 27)),
"area" = 1:3,
"dv1" = rnorm(54),
"dv2" = rnorm(54),
"dv3" = rnorm(54))
data$area <- as.factor(data$area)
data$id <- as.factor(data$id)
Here's what I've tried
library(ggplot2)
ggplot(data,aes(x=area,y=dv1,col=intervention)) +
geom_point() +
geom_boxplot(alpha=0.2) +
facet_wrap(~id) +
ggtitle("DV1") +
xlab("Intervention") +
ylab("DV1")
Instead of the red points overlaying the red boxplot, they're all over the place. How do I fix this?
Edit: I used the jitter options that u/eipi10 suggested and this is what I have now.
ggplot(data,aes(x=area,y=dv1,col=intervention)) +
geom_point(position=position_jitterdodge(dodge.width=0.75, jitter.height=0, jitter.width=0.25), alpha=0.6) +
geom_boxplot(alpha=0.2, size=0.3) +
facet_wrap(~id) +
ggtitle("DV1") +
xlab("Area") +
ylab("DV1")
question from:
https://stackoverflow.com/questions/65946477/how-do-i-plot-mixed-effects-linear-regression 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…