title: How to plot several rows from a dataframe with ggplot?
body: <p>I try to plot with ggplot2 the monthly wheat prices in France in each agricultural year in 1845-1848. I am given the following table:</p>
  
  <pre><code>year,January,February,March,April,May,June,July,August,September,October,November,December
  1845,,,,,,,,20.17,20.3,21.51,22.27,22.32
  1846,22.36,22.65,22.42,22.26,22.48,22.93,22.92,24,24.9,25.97,27.59,28.01
  1847,30.16,33.5,37.69,37.54,37.98,33.5,28.42,23.63,22.57,22.01,20.76,20.36
  1848,20.01,19.34,18.12,16.59,16.58,15.88,15.67,,,,,
  </code></pre>
  
  <p>I want to plot the data with lines and points the following way:</p>
  
  <ol>
  <li>have the months on x and the prices on y</li>
  <li>group by year: each year gets its own line (four lines)</li>
  <li>where there is no data (NA) there should be no point and no line</li>
  </ol>
  
  <p>This task is extremely easy to solve in libreoffice calc in just a few clicks: select all table > insert chart > line > Points and line > next > data series in rows + first row as label + first column as label > finish (8 clicks).</p>
  
  <p>But I can't seem to find a way to do the same using R and ggplot2. </p>
  
  <p>I need to be able to solve this in R to apply further statistical analysis to the series.</p>
  
  <p>I have tried the following solution:</p>
  
  <pre><code># Reading the data
  wheat &lt;- read_csv("data/wheat.csv")
  
  # Plotting
  wheat %&gt;%
    ggplot(aes(x=wheat[0,])) +
    geom_line(aes(y=as.numeric(wheat[1,]), group="year")) +
    geom_point()
  </code></pre>
  
  <p>I would think that a code like this would produce the desired plot. </p>
  
  <p>But I get the error </p>
  
  <blockquote>
    <p>"Don't know how to automatically pick scale for object of type
    tbl_df/tbl/data.frame. Defaulting to continuous. Error: Aesthetics
    must be either length 1 or the same as the data (4): y, x".</p>
  </blockquote>
  
  <p>I understand that ggplot sees a 4x13 tibble and awaits that y have the same length (4). </p>
  
  <p>But I want to feed him the table rows as y values.</p>
  
  <p>Thanks for any help!</p>
  
  <p>EDIT</p>
  
  <p>My question is not a duplicate of "<a href="https://stackoverflow.com/questions/19011959/constructing-a-line-graph-using-ggplot2">Constructing a line graph using ggplot2</a>". </p>
  
  <p>Though it is the same general problem - plotting several vectors of one dataframe and for that preparing the data to be usable with ggplot - the initial data is very different: mine is historical data that must be organized chronologically, thus the need to specify the <code>levels</code> by which the data will be organized on x. Plus the initial table is particular and required special treatment with <code>gather</code>. </p>
  
  <p>Here the whole working code for reference:</p>
  
  <pre><code>library(tidyverse)
  
  # Reading into a tibble:
  wheat &lt;- read_csv("year,January,February,March,April,May,June,July,August,September,October,November,December
  1845,,,,,,,,20.17,20.3,21.51,22.27,22.32
  1846,22.36,22.65,22.42,22.26,22.48,22.93,22.92,24,24.9,25.97,27.59,28.01
  1847,30.16,33.5,37.69,37.54,37.98,33.5,28.42,23.63,22.57,22.01,20.76,20.36
  1848,20.01,19.34,18.12,16.59,16.58,15.88,15.67,,,,,")
  
  # Tidying:
  wheat_tidy &lt;- wheat %&gt;% gather(month, price, -year)
  
  # Leveling:
  wheat_tidy$month &lt;- factor(wheat_tidy$month, levels = c("January","February","March","April","May","June","July","August","September","October","November","December"))
  
  # Plotting:
  wheat_tidy %&gt;%
    ggplot(aes(x=month, y=price, group=year, color=as.factor(year))) +
    geom_line() +
    geom_point()
  </code></pre>