I have several variables measured twice and I want to display them in a chart showing boxplots as well as individual values (using geom_dotplot) where the values from the two measurements in the same variable are connected by a customisable line.
I have found a solution using jittered geom_point (basically generating a new data) but if at all possible, I would like to have a dotplot.
Simplified code to create the chart for 5 subjects and 2 variables
library(ggplot2)
dat <- data.frame(subject = c(1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5),
measurement = c("M1", "M1", "M1", "M1", "M1", "M2", "M2", "M2", "M2", "M2",
"M1", "M1", "M1", "M1", "M1", "M2", "M2", "M2", "M2", "M2"),
variable = c("Var1", "Var1", "Var1", "Var1", "Var1", "Var1", "Var1", "Var1", "Var1", "Var1",
"Var2", "Var2", "Var2", "Var2", "Var2", "Var2", "Var2", "Var2", "Var2", "Var2"),
value = c(20, 15, 21, 23, 15, 22, 21, 31, 24, 17, 26, 10, 23, 22, 19, 29, 15, 25, 29, 19))
ggplot(dat, aes(variable, value, colour = measurement)) +
geom_boxplot(outlier.shape = NA) +
geom_dotplot(aes(fill = measurement),
binaxis = "y", binwidth = 0.5, stackdir = "center",
position = position_dodge(0.75))
The current chart where I would like to have lines connecting paired red and cyan dots between the two measurements within a variable, as shown for Var1 where I drawn them by hand:

Thanks, PB

