I want the plot a mixed models output (2x2 design). Everything is working well, I just want the line for group A to be a dotted one and the line for group B to be a solid one.
Could anybody help?
Here is the code I used:
library(ggeffects)
dput(data)
structure(list(subj = c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L,
3L, 3L, 4L, 4L, 4L, 4L), item = c(1L, 1L, 2L, 2L, 1L, 1L, 2L,
2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L), gpR2 = c(0, 83.4, 132, 69.3,
95.8, 97.4, 36.3, 50.1, 100.2, 40, 87.6, 61.5, 108.8, 47.7, 37.4,
46.3), lang = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L), levels = c("c", "d"), class = "factor", contrasts = structure(c(1,
-1), dim = 2:1, dimnames = list(c("c", "d"), NULL))), type = structure(c(2L,
1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L), levels = c("n",
"v"), class = "factor", contrasts = structure(c(1, -1), dim = 2:1, dimnames = list(
c("n", "v"), NULL)))), row.names = c(NA, -16L), class = "data.frame")
mmgpR2 <-lmer(gpR2 ~ lang*type + (1+type|subj) + (1+type*lang|item), data=data)
plot3 = ggpredict(mmgpR2, terms = c("type", "lang"))
plot(plot3, connect.lines = TRUE, colors = "bw") +
ggeasy::easy_center_title()+
ggtitle("Nom_vs_Verb") +
xlab("Type") + ylab("Time")+
scale_shape_discrete(name="Language",labels=c("Group A","Group B"))+
easy_all_text_size(15)+
easy_all_text_color("black")
As a first step, you could map the "group"
column of the plot3
data on the linetype
aes too, then set your desired linetypes using scale_linetype_manual
:
library(ggplot2)
library(ggeasy)
plot(plot3, connect.lines = TRUE, colors = "bw") +
aes(linetype = .data[["group"]]) +
ggeasy::easy_center_title() +
ggtitle("Nom_vs_Verb") +
xlab("Type") + ylab("Time") +
scale_shape_discrete(
name = "Language",
labels = c("Group A", "Group B")
) +
easy_all_text_size(15) +
easy_all_text_color("black") +
scale_linetype_manual(
values = c("dotted", "solid"),
name = "Language",
labels = c("Group A", "Group B")
)