I have code that plots paired points and also graphs half violin and box plots of pretest and posttest scores. I added lines between the paired points, but I am having difficulty with adding an arrow to the lines and changing the color depending on whether the score decreased or increased.
Below is my code and an image of my graph.
f5 <- ggplot(data = d, aes(y = y)) +
#Add geom_() objects
geom_point(data = d %>% filter(x =="1"), aes(x = xj), color = 'dodgerblue', size = 1.5,
alpha = .6) +
geom_point(data = d %>% filter(x =="2"), aes(x = xj), color = 'darkorange', size = 1.5,
alpha = .6) +
geom_line(aes(x = xj, group = id), color = 'lightgray', alpha = .3) +
geom_half_boxplot(
data = d %>% filter(x=="1"), aes(x=x, y = y), position = position_nudge(x = -.25),
side = "r",outlier.shape = NA, center = TRUE, errorbar.draw = FALSE, width = .2,
fill = 'dodgerblue') +
geom_half_boxplot(
data = d %>% filter(x=="2"), aes(x=x, y = y), position = position_nudge(x = .15),
side = "r",outlier.shape = NA, center = TRUE, errorbar.draw = FALSE, width = .2,
fill = 'darkorange') +
geom_half_violin(
data = d %>% filter(x=="1"),aes(x = x, y = y), position = position_nudge(x = -.3),
side = "l", fill = 'dodgerblue') +
geom_half_violin(
data = d %>% filter(x=="2"),aes(x = x, y = y), position = position_nudge(x = .3),
side = "r", fill = "darkorange") +
#Define additional settings
scale_x_continuous(breaks=c(1,2), labels=c("Pre-Test", "Post-Test"), limits=c(0, 3)) +
xlab("Test") + ylab("Score") +
ggtitle("Before and After Scores with box- and violin plots") +
theme_classic()+
coord_cartesian(ylim=c(y_lim_min, y_lim_max))