xlim_lower <- -2.2
xlim_upper <- 2.2
ylim_lower <- -15
ylim_upper <- 55
set.seed(1) # seed for constant jitter
p_xy_study <- score_data |>
mutate(study_num = ifelse(study == 'alone', 0, 1)) |>
ggplot(aes(x = study_num, y = score)) +
geom_jitter(aes(colour = study), height = 0, alpha = 0.25, width = 0.1, size = 5) +
scale_x_continuous(limits = c(xlim_lower, xlim_upper), expand = c(0, 0)) +
scale_y_continuous(limits = c(ylim_lower, ylim_upper), expand = c(0, 0)) +
geom_segment(x = xlim_lower, xend = xlim_upper, y = 0, yend = 0,
arrow = arrow(ends = 'both', length = unit(12, 'pt')), colour = 'black') +
geom_segment(x = 0, xend = 0, y = ylim_lower, yend = ylim_upper,
arrow = arrow(ends = 'both', length = unit(12, 'pt')), colour = 'black') +
stat_summary(fun = mean, geom = 'point', colour = 'black', size = 8, show.legend = FALSE) +
scale_colour_manual(values = pal) +
theme(
panel.grid.minor = element_blank(),
legend.position = 'bottom'
) +
labs(
x = 'study (in numeric space)'
) +
guides(colour = guide_legend(override.aes = list(alpha = 1))) +
geom_abline(slope = mean_others - mean_alone, intercept = mean_alone, colour = 'black', linewidth = 2) +
NULL
p_xy_study