title: R Ggplot2: Draw lines between unrelated points
body: <p>I want to draw a line between some unrelated points.</p>
  <p>This is my code now:</p>
  <pre><code>probpostest %&gt;%
    filter(prev==15) %&gt;% 
    mutate(
      stat=replace(stat,stat==&quot;prevalencia&quot;,&quot;Prevalencia&quot;),
      stat=replace(stat,stat==&quot;probpostestpositivo&quot;,&quot;Probabilidad\nPostest\nPositivo&quot;),
      stat=replace(stat,stat==&quot;probpostestnegativo&quot;,&quot;Probabilidad\nPostest\nNegativo&quot;),
      group=replace(group,group==&quot;proven&quot;,&quot;Confirmada&quot;),
      group=replace(group,group==&quot;proven_likely&quot;,&quot;Confirmada o\nprobable&quot;),
      group=replace(group,group==&quot;proven_likely_possible&quot;,&quot;Confirmada,\nprobable o\nposible&quot;)) %&gt;% 
    mutate(across(stat, factor, levels=c(&quot;Prevalencia&quot;,&quot;Probabilidad\nPostest\nPositivo&quot;,&quot;Probabilidad\nPostest\nNegativo&quot;)),
           across(c(lower,upper), as.numeric),
           lower=lower/100,
           upper=upper/100) %&gt;%
  
    ggplot(aes(x=stat,
               y=if_else(is.na(estimator*100),
                         100,
                         estimator*100),
               ymin=lower,ymax=upper,color=stat)) +
    geom_point() + 
    geom_text(aes(label=if_else(is.na(estimator),
                                &quot;NC&quot;,
                                paste0(sprintf(&quot;%2.2f&quot;,estimator*100),&quot;%&quot;)),
                  vjust=if_else(is.infinite(estimator),
                                1,
                                0.5),
                  hjust=-0.25),
              show.legend = FALSE,
              size=4) + # Esta línea quita la &quot;a&quot; de las leyendas
    labs(x=NULL,y=NULL,title = &quot;Figura 5. Probabilidades pre-test y post-test.&quot;,
         caption=&quot;Prevalencia: probabilidad pre-test.\n\nProbabilidad pos-test positivo y negativo: probabilidad de tener candidiasis invasiva después de obtener un resultado positivo o negativo, respectivamente.\n\nNC: no calculable.&quot;)+
    facet_grid(group ~ test,
               scales = &quot;free_y&quot;,
               switch = &quot;y&quot;
    ) +
    theme_minimal()+
    theme(plot.title = element_text(hjust = 0.5),
          plot.caption = element_text(hjust = 0),
          legend.position = &quot;none&quot;,
          strip.text = element_text(face=&quot;bold&quot;)) +
    scale_y_continuous(position = &quot;right&quot;) +
    scale_color_brewer(palette = &quot;Set1&quot;)
  </code></pre>
  <p>I get this:
  <a href="https://i.stack.imgur.com/MweZN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MweZN.png" alt="Figure1" /></a></p>
  <p>and I'd like something like this (done with Paint):
  <a href="https://i.stack.imgur.com/pnVxc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pnVxc.png" alt="enter image description here" /></a></p>
  <p>I tried adding <code>geom_line(aes(x = stat, group=group)) +</code> and I could get this, which is not what I need.</p>
  <p><a href="https://i.stack.imgur.com/s6D0k.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/s6D0k.png" alt="enter image description here" /></a></p>
  <p>I wonder how I could link the points of my interest and then plot a line between them.
  Thank you for your help!</p>
  <p><strong>Reprex:</strong></p>
  <pre><code>structure(list(prev = c(15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 
  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 
  15, 10, 10, 10, 10, 10, 10, 10, 10, 10, 5, 5, 5, 5, 5, 5, 5, 
  5, 5), group = c(&quot;proven&quot;, &quot;proven&quot;, &quot;proven&quot;, &quot;proven_likely&quot;, 
  &quot;proven_likely&quot;, &quot;proven_likely&quot;, &quot;proven_likely_possible&quot;, &quot;proven_likely_possible&quot;, 
  &quot;proven_likely_possible&quot;, &quot;proven&quot;, &quot;proven&quot;, &quot;proven&quot;, &quot;proven_likely&quot;, 
  &quot;proven_likely&quot;, &quot;proven_likely&quot;, &quot;proven_likely_possible&quot;, &quot;proven_likely_possible&quot;, 
  &quot;proven_likely_possible&quot;, &quot;proven&quot;, &quot;proven&quot;, &quot;proven&quot;, &quot;proven_likely&quot;, 
  &quot;proven_likely&quot;, &quot;proven_likely&quot;, &quot;proven_likely_possible&quot;, &quot;proven_likely_possible&quot;, 
  &quot;proven_likely_possible&quot;, &quot;proven&quot;, &quot;proven&quot;, &quot;proven&quot;, &quot;proven&quot;, 
  &quot;proven&quot;, &quot;proven&quot;, &quot;proven&quot;, &quot;proven&quot;, &quot;proven&quot;, &quot;proven&quot;, &quot;proven&quot;, 
  &quot;proven&quot;, &quot;proven&quot;, &quot;proven&quot;, &quot;proven&quot;, &quot;proven&quot;, &quot;proven&quot;, &quot;proven&quot;
  ), test = c(&quot;T2Candida&quot;, &quot;T2Candida&quot;, &quot;T2Candida&quot;, &quot;T2Candida&quot;, 
  &quot;T2Candida&quot;, &quot;T2Candida&quot;, &quot;T2Candida&quot;, &quot;T2Candida&quot;, &quot;T2Candida&quot;, 
  &quot;Hemocultivo&quot;, &quot;Hemocultivo&quot;, &quot;Hemocultivo&quot;, &quot;Hemocultivo&quot;, &quot;Hemocultivo&quot;, 
  &quot;Hemocultivo&quot;, &quot;Hemocultivo&quot;, &quot;Hemocultivo&quot;, &quot;Hemocultivo&quot;, &quot;T2Candida + Hemocultivo&quot;, 
  &quot;T2Candida + Hemocultivo&quot;, &quot;T2Candida + Hemocultivo&quot;, &quot;T2Candida + Hemocultivo&quot;, 
  &quot;T2Candida + Hemocultivo&quot;, &quot;T2Candida + Hemocultivo&quot;, &quot;T2Candida + Hemocultivo&quot;, 
  &quot;T2Candida + Hemocultivo&quot;, &quot;T2Candida + Hemocultivo&quot;, &quot;T2Candida&quot;, 
  &quot;T2Candida&quot;, &quot;T2Candida&quot;, &quot;Hemocultivo&quot;, &quot;Hemocultivo&quot;, &quot;Hemocultivo&quot;, 
  &quot;T2Candida + Hemocultivo&quot;, &quot;T2Candida + Hemocultivo&quot;, &quot;T2Candida + Hemocultivo&quot;, 
  &quot;T2Candida&quot;, &quot;T2Candida&quot;, &quot;T2Candida&quot;, &quot;Hemocultivo&quot;, &quot;Hemocultivo&quot;, 
  &quot;Hemocultivo&quot;, &quot;T2Candida + Hemocultivo&quot;, &quot;T2Candida + Hemocultivo&quot;, 
  &quot;T2Candida + Hemocultivo&quot;), stat = c(&quot;prevalencia&quot;, &quot;probpostestpositivo&quot;, 
  &quot;probpostestnegativo&quot;, &quot;prevalencia&quot;, &quot;probpostestpositivo&quot;, 
  &quot;probpostestnegativo&quot;, &quot;prevalencia&quot;, &quot;probpostestpositivo&quot;, 
  &quot;probpostestnegativo&quot;, &quot;prevalencia&quot;, &quot;probpostestpositivo&quot;, 
  &quot;probpostestnegativo&quot;, &quot;prevalencia&quot;, &quot;probpostestpositivo&quot;, 
  &quot;probpostestnegativo&quot;, &quot;prevalencia&quot;, &quot;probpostestpositivo&quot;, 
  &quot;probpostestnegativo&quot;, &quot;prevalencia&quot;, &quot;probpostestpositivo&quot;, 
  &quot;probpostestnegativo&quot;, &quot;prevalencia&quot;, &quot;probpostestpositivo&quot;, 
  &quot;probpostestnegativo&quot;, &quot;prevalencia&quot;, &quot;probpostestpositivo&quot;, 
  &quot;probpostestnegativo&quot;, &quot;prevalencia&quot;, &quot;probpostestpositivo&quot;, 
  &quot;probpostestnegativo&quot;, &quot;prevalencia&quot;, &quot;probpostestpositivo&quot;, 
  &quot;probpostestnegativo&quot;, &quot;prevalencia&quot;, &quot;probpostestpositivo&quot;, 
  &quot;probpostestnegativo&quot;, &quot;prevalencia&quot;, &quot;probpostestpositivo&quot;, 
  &quot;probpostestnegativo&quot;, &quot;prevalencia&quot;, &quot;probpostestpositivo&quot;, 
  &quot;probpostestnegativo&quot;, &quot;prevalencia&quot;, &quot;probpostestpositivo&quot;, 
  &quot;probpostestnegativo&quot;), estimator = c(0.158, 0.635718612096565, 
  0.0361721611721612, 0.404, 0.637998056365403, 0.351610095735422, 
  0.561, 0.908822796377835, 0.472165444270771, 0.158, 1, 0.101195559350982, 
  0.404, 1, 0.351610095735422, 0.561, 1, 0.534908358936328, 0.158, 
  NA, 0.0184192119375146, 0.404, NA, 0.321802457897132, 0.561, 
  NA, 0.472165444270771, 0.1, 0.508196721311476, 0.0217391304347826, 
  0.1, 1, 0.0625, 0.1, NA, 0.010989010989011, 0.05, 0.328621908127209, 
  0.0104166666666667, 0.05, 1, 0.0306122448979592, 0.05, NA, 0.00523560209424084
  ), lower = c(&quot;7.5&quot;, NA, NA, &quot;27.6&quot;, NA, NA, &quot;42.4&quot;, NA, NA, &quot;7.5&quot;, 
  NA, NA, &quot;27.6&quot;, NA, NA, &quot;42.4&quot;, NA, NA, &quot;7.5&quot;, NA, NA, &quot;27.6&quot;, 
  NA, NA, &quot;42.4&quot;, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
  NA, NA, NA, NA, NA, NA, NA, NA), upper = c(&quot;27.9&quot;, NA, NA, &quot;54.2&quot;, 
  NA, NA, &quot;69.3&quot;, NA, NA, &quot;27.9&quot;, NA, NA, &quot;54.2&quot;, NA, NA, &quot;69.3&quot;, 
  NA, NA, &quot;27.9&quot;, NA, NA, &quot;54.2&quot;, NA, NA, &quot;69.3&quot;, NA, NA, NA, NA, 
  NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA
  )), row.names = c(NA, -45L), class = c(&quot;tbl_df&quot;, &quot;tbl&quot;, &quot;data.frame&quot;
  ))
  </code></pre>