Here you add the time group in geom_point
.
ggplot(data, aes(exp, result, fill=time)) +stat_boxplot(width=0.5, position = position_dodge(1)) +geom_boxplot(position = position_dodge(1), outlier.shape = NA)+geom_point(aes(fill = time, group = time), color="black", position = position_jitterdodge(jitter.width = .1, dodge.width = 1))
You could use geom_jitter
like this:
exp <- rep(c("smile", "neutral", "depressor"), each=5, times=2)time <- rep(c("before", "after"), each = 15)result <- rnorm(15, mean=50, sd=4)result <- append(result, c(rnorm(15, mean=47, sd=3)))data <- data.frame(exp, time, result)library(ggplot2)ggplot(data, aes(exp, result, fill=time)) + geom_boxplot() +geom_jitter()
Created on 2022-08-30 with reprex v2.0.2