title: Combining geom_point and geom_line with position_jitterdodge for two grouping factors
body: <p>I've tried several suggestions based on several posts on here, as well as reading through the ggplot2 documentation, but this question is slightly different, and I haven't found a solution yet.</p>
  
  <p>Here's a snippet of code to make a melted dataframe similar to the one I'm working with:</p>
  
  <pre><code>a &lt;- c(1,2,3,4,5,6,1,2,3,4,5,6)
  b &lt;- c("loss", "draw", "win", "draw", "loss", "win", "loss", "draw", "win", "draw", "loss", "win")
  c &lt;- c(2,3,5,4,4,5,4,4,3,5,2,4)
  d &lt;- c(rep("x", 6), rep("y", 6))
  temp &lt;- data.frame(a,b,c,d)
  </code></pre>
  
  <p>What I want is to create a dot plot with b on the x-axis, c on the y-axis, with the points on the x-axis grouped by d, and lines between them grouped by a. If we start by just putting the points on the graph like so, it comes out fine:</p>
  
  <pre><code>ggplot(temp, aes(x=b, y=c, fill=d, colour=d))+
    geom_point(position=position_jitterdodge())
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/9zBjp.png" rel="noreferrer">This is the dot plot I get, which is how I want it to look.</a> The points are colour-coded according to factor d, and moreover they're jitterdodged to one side so that x is on the left and y is on the right.</p>
  
  <p>Now, all I want is to connect the points with lines according to factor a. <a href="https://i.stack.imgur.com/vt2Nd.png" rel="noreferrer">This is a mocked-up version I made in MS Paint</a> of how it should look. Adding a geom_line and setting the geom_line group to a should work...</p>
  
  <pre><code>ggplot(temp, aes(x=b, y=c, fill=d, colour=d))+
    geom_point(position=position_jitterdodge())+
    geom_line(aes(group=a),position=position_jitterdodge())
  </code></pre>
  
  <p>...but it doesn't come out right. The lines it creates are the right length to connect the correct points, but they barely even touch them, it looks like they're on the graph at random. I would add another screenshot, but don't have the privileges yet.</p>
  
  <p>Moreover, if I change the group aesthetic to be in the overall aesthetic like so:</p>
  
  <pre><code>ggplot(temp, aes(x=b, y=c, fill=d, colour=d, aes(group=a)))+
    geom_point(position=position_jitterdodge())+
    geom_line(position=position_jitterdodge())
  </code></pre>
  
  <p>...then the points are switched around so that they're in the wrong position. And in any case, the lines still don't join up with the points fully.</p>
  
  <p>I have also tried specifying width and jitter.width values in the position_jitterdodge() part, and the lines and points still don't join up properly. I have also read through the ggplot2 documentation, several previous stackoverflow questions, and tried out most combinations of position_jitter, position_dodge, geom_jitter, etc., but no luck so far. </p>
  
  <p>Any help would be greatly appreciated.</p>