title: How do I plot multiple lines (by levels of factor) for year series?
body: <p>I'm fairly new to R and I've been having trouble with a plot.</p>
  
  <p>I'm trying to create a line plot with:
  $YEAR on the X axis
  $METRIC on the Y axis
  a different-colored line for each country (meaning, a total of 3 lines on the same plot)</p>
  
  <p>$COUNTRY is a factor with 3 levels</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>COUNTRY YEAR    METRIC
  USA     2000    14.874
  USA     2001    15.492
  USA     2002    13.091
  USA     2003    14.717
  CAN     1999    15.031
  CAN     2000    14.343
  CAN     2001    12.972
  CAN     2002    13.216
  SWE     1999    14.771
  SWE     2000    17.033
  SWE     2001    15.932
  SWE     2002    14.516
  SWE     2003    15.655</code></pre>
  </div>
  </div>
  </p>
  
  <p>When I create the plot with</p>
  
  <blockquote>
    <p>plot(df$YEAR, df$METRIC, col=df$COUNTRY, type="p")</p>
  </blockquote>
  
  <p>I get a plot with points for each (x,y) combination and different color for each level of the factor $COUNTRY</p>
  
  <p>However, when I try to get a line for each country, with</p>
  
  <blockquote>
    <p>plot(df$YEAR, df$METRIC, col=df$COUNTRY, type="l")</p>
  </blockquote>
  
  <p>I get one non-stopping line, that starts with the 4 observations of "USA" and then goes back to the first year of the next country ("CAN").</p>
  
  <p><img src="https://i.stack.imgur.com/56zxT.png" alt="screenshot attached"></p>
  
  <p><strong>Can anyone explain why is this happening?
  Is it possible to create this plot using only the pre-built functions?</strong></p>
  
  <p>Thank you in advance for any assistance.</p>