title: Connect start and end between groups within segmented lines in R?
body: <p>My data frame looks as follows:</p>
  
  <pre><code>&gt; df
    person step start end
  1    sam    A     0   4
  2    sam    B     4   6
  3   greg    A     2   7
  4   greg    B     7  11
  </code></pre>
  
  <p>And I plot the following chart:</p>
  
  <pre><code>library(ggplot2)
  library(dplyr)
  library(tidyr)
  
  ggplot(df, aes(colour=step)) + 
    geom_segment(aes(x=start, xend=end, y=person, yend=person), size=3) +
    xlab("Duration")
  </code></pre>
  
  <p>Now, I want to connect each start and end between sam and greg and label it with the difference.</p>
  
  <p>The expected graphic should look something like this:</p>
  
  <p><a href="https://i.stack.imgur.com/P511b.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/P511b.png" alt="enter image description here"></a></p>
  
  <p>The problem is that I don't know how I can draw the lines without passing x and y coordinates. The y coordinates are determined by the grouping (person).</p>