Dear users,
I have a problem with error bars in ggplot2.
I want to plot an interaction between continuous [iv] and nominal [condition] variable.
I use such a code
iv = runif(n = 100, min = 1, max = 7)
condition <- rep(letters[1:2], length.out = 100)
y = runif(n = 100, min = 1, max = 100)
df <- data.frame(iv, condition, y)
lm20 <- lm(y ~ condition * iv, data = df)
summary(lm20)
df$condition <- as.factor(df$condition)
ggeffect(lm20, terms = c("condition", "iv")) %>%
plot(show.title = FALSE) +
stat_summary(fun.y = mean,
geom = "point") +
stat_summary(fun.y = mean,
geom = "line") +
stat_summary(fun.data = mean_cl_boot,
geom = "errorbar") +
scale_y_continuous("Voting intentions", limits = c(0, 100)) +
scale_colour_discrete(name = "Control", labels = c("Low", "Medium", "High")) +
scale_x_discrete("Condition", labels = c("Low","High")
And this is what I get:
I encounter two problems
- Error bars and lines do not match
- I cannot change the labels on the X axis
I would be very grateful for your help - I've spent almost two days looking for an answer already.
Many thanks!