I try to connect jittered points between measurements from two different methods (measure) on an x-axis. These measurements are linked to one another by the probands (a), that can be separated into two main groups, patients (pat) and controls (ctr), My df is like that:
set.seed(1)
df <- data.frame(a = rep(paste0("id","_",1:20), each=2), value = sample(1:10,40,rep=TRUE), measure= rep(c("a","b"),20), group= rep(c("pat","ctr"),each=2,10))
I tried
library(ggplot2)
ggplot(df,aes(measure,value,fill=group)) +
geom_point(position=position_jitterdodge(jitter.width=0.1,jitter.height=.1, dodge.width=.75), shape=1) +
geom_line(aes(group=a),position=position_dodge(.75))
Created on 2020-01-13 by the reprex package (v0.3.0)
I used the fill aesthetic in order to separate the jittered dots from both groups (pat and ctr). I realised that when I put the group=a aesthetics into the ggplot main call, then it doesn't separate as nicely, but seems to link better to the points.
My question: Is there a way to better connect the lines to the (jittered) points, but keeping the separation of the two main groups, ctr and pat?
Thanks a lot.