0

I'm drawing some figures that have overlayed points across two groups, which are dodged to make the groups clear. One of the groups' points are shown across two experimental conditions (shown on the x axis), and I want to join up these two sets of points using lines. I also want to make the means and the data points distinct by filling in the means and leaving the individual data points empty. Basically, I can't get my 'dodged' points to join up neatly with the lines, even when I dodge the lines as well.

As an example using sample data:

 group <- c("high", "high", "high", "low", "low", "low", "high", "high", "high", "low", "low", "low")
 condition <- c("c1", "c1", "c1", "c1", "c1", "c1", "c2", "c2", "c2", "c2", "c2", "c2")
 value <- c(.91, .63, .5, NA, NA, NA, .93, .76, .43, .5, .6, .8)
 subj <- c("s1", "s2", "s3", "s4", "s5", "s6")

 sample.data <- data.frame(group, condition, value, subj)


 ggplot(sample.data, aes(x=condition, y=value)) +
   geom_point(aes(colour=group, shape = group), size = 2, position = position_dodge(.1)) +
   scale_shape_manual(values=c(2,1)) + 
   geom_line(aes(group=subj), colour='lightgrey') +
   stat_summary(fun.y=mean, geom = "point", aes(shape=group, fill = group),
           size=5, position = position_dodge(.1)) +
   stat_summary(fun.y = mean, aes(group=group, colour=group), geom='line', 
 size=.8, position = position_dodge(.1))

Example figure

As you can see in the example figure, the lines are not joining up the points, even though I have 'dodged' the line as well. Is there a neat way to get ggplot to do this?

Many thanks!

camille
  • 16,432
  • 18
  • 38
  • 60
Catherine Laing
  • 475
  • 6
  • 18
  • Which points do you want lines between that don't already have them? The green points only exist at the second condition...what would they link to? – camille Mar 07 '19 at 16:19
  • @camille just the red triangles. So the lines that I want are all there in the figure, they just don't join up the points neatly: they look kind of untidy so I'd like them to 'touch' the red triangles, rather than hovering off to the bottom/top (it looks a lot worse in my real figure!) – Catherine Laing Mar 07 '19 at 16:21
  • Does this answer your question? [using position\_dodge with geom\_line](https://stackoverflow.com/questions/54775878/using-position-dodge-with-geom-line) In short: move `` to `ggplot(aes(<>))` – jan-glx Nov 26 '21 at 09:44

0 Answers0