R beginner here :) Took me ages to finally get the code for this raincloud plot to work, but whatever I try, the colours I define in the scale color manual do not add up with the colours for the scatterplot and the colour legend. I want Healthy Controls to be green, MDD to be blue and BD pink, but even though the boxplot and violin plot parts are mapped to the correct colours, the scatterplot points and also the colour legend in the plot, for some reason, define the Healthy Controls as pink, MDD as green, and BD as blue. I can't get to the bottom of this. Also, the colour legend uses the factor names of the Diagnosis variable instead of the labels I defined in the scale_color_manual function at the beginning of the code. I guess something in the geom_point function is overriding the original colour manual, but i don't know what it is. Can anyone help?
Here's the code I used:
ggplot (BAG_plots, aes(x = time.j, y = BAG, fill = Diagnosis)) +
theme_classic() +
scale_x_continuous(breaks = c(1,2), labels=c("Baseline", "Follow Up"), limits=c(0, 3)) +
labs(x = "Time", y = "Brain Age Gap", colour = "Diagnosis") +
ggtitle("BAG over time by diagnosis") +
theme(text=element_text(family="Bahnschrift", colour = 'gray10'),
axis.text.x = element_text(colour = 'gray10'),
axis.text.y = element_text(colour = 'gray10')) +
scale_color_manual(name = "Diagnosis",
values = c("springgreen4", "royalblue4", "deeppink3"),
labels = c("Healthy Controls","MDD","BD"),
guide = "legend") +
geom_line (data = BAG_plots, aes(x = time.j, y = BAG, group = ID), colour = "lightgray", alpha = .3) +
geom_point (data = BAG_plots, aes(x = time.j, y = BAG, colour = Diagnosis),
size = 3, pch = 21, alpha = .5, colour = "gray10") +
geom_half_boxplot(data = BAG_plots %>% filter(time=="1" & Diagnosis=="Healthy Controls"),
aes(x = time, y = BAG), position = position_nudge(x = -.25), side = "l",
outlier.shape = NA, center = TRUE, errorbar.draw = FALSE,
width = .2, alpha = .5, fill = "springgreen4", colour = "gray10") +
geom_half_boxplot (data = BAG_plots %>% filter (time=="1" & Diagnosis=="Major Depressive Disorder"),
aes(x = time, y = BAG), position = position_nudge(x = -.35), side = "l",
outlier.shape = NA, center = TRUE, errorbar.draw = FALSE,
width = .2, alpha = .5, fill = "navyblue", colour = "gray10") +
geom_half_boxplot (data = BAG_plots %>% filter(time=="1" & Diagnosis=="Bipolar Disorder"),
aes(x = time, y = BAG), position = position_nudge(x = -.45), side = "l",
outlier.shape = NA, center = TRUE, errorbar.draw = FALSE,
width = .2, alpha = .5, fill = "deeppink3", colour = "gray10") +
etc