title: How to connect dots with lines with ggplot2
body: <p><strong>Solved!</strong></p>
  
  <blockquote>
    <p>Thank you @Gregor and @eipi10. I solved this problem by </p>
    
    <ol>
    <li><p>Converting the dataframe to <code>long</code> format:</p>
    
    <p><code>dat.long &lt;-poverty %&gt;% gather(key, value, -Year)</code></p></li>
    <li><p>Filter out all the <code>NA</code>s:</p>
    
    <p><code>dat.long&lt;-dat.long[complete.cases(dat.long), ]</code></p></li>
    <li><p>ggplot!</p></li>
    </ol>
  </blockquote>
  
  <hr>
  
  <hr>
  
  <hr>
  
  <h2>Preface</h2>
  
  <p>Unlike <a href="https://stackoverflow.com/questions/11404959/connecting-points-with-lines-in-ggplot2-in-r">other</a> questions, I have a quite odd data frame with several <code>NA</code> values:</p>
  
  <p><a href="https://i.stack.imgur.com/AMv1s.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AMv1s.png" alt="IMAGE 1"></a> </p>
  
  <p>When I <code>geom_line</code> them:</p>
  
  <pre><code>ggplot(poverty, aes(Year))+
    geom_line(aes(y = poverty$Poverty..BM.2002.....of.world.population., colour = "2002 Poverty"))+
    geom_line(aes(y = poverty$Extreme.Poverty..BM.2002.....of.world.population., colour = "2002 Extreme Poverty")) +
    geom_line(aes(y = poverty$Less.than.1.90..per.day..World.Bank..2015......of.world.population., colour = "2015 Poverty"))
  </code></pre>
  
  <p>I get discontinued lines:</p>
  
  <p><a href="https://i.stack.imgur.com/nmohl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nmohl.png" alt="Discontinued lines"></a></p>
  
  <p>There are SO posts suggesting plot points first, then connect them by <code>group</code>. I thought it is a good idea when I got something like this:</p>
  
  <p><a href="https://i.stack.imgur.com/niUuU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/niUuU.png" alt="Scatter plot"></a></p>
  
  <h2>Problem</h2>
  
  <p>How do I connect the dots? (<em>note, I don't have <code>factor</code> class column in my dataframe, so I can't really do it by <code>group=</code></em>)</p>
  
  <p><strong>Desired output</strong>:</p>
  
  <p><a href="https://i.stack.imgur.com/1KYXU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1KYXU.png" alt="Desired Output"></a></p>
  
  <h2>Side Request</h2>
  
  <p>How do I change the legend title?</p>
  
  <p>Thank you!</p>