For this data:
set.seed(123)
df <- data.frame(
ID = 1:50,
Q = rnorm(50),
A = rnorm(50,1)
)
I would like to connect the pairwise observations in Q
and A
grouped by ID
. Here's what I have so far:
df %>%
pivot_longer(-ID) %>%
ggplot(aes(x = factor(name), y = value, fill = factor(name)))+
geom_jitter(width = 0.1, alpha = 0.5, col = "blue")+
geom_line(aes(group = ID),
alpha = 0.5)
- (i) I'm not sure the connecting lines are really between the observations with the same
ID
- (ii) the starting points and end points of the connecting lines are not jittered, therefore they do not always coincide with the dots.
How can these issue be dealt with?