title: Plot multiple data sets by group with lines in R
body: <p>I'm somewhat surprised that I can't find a solution to this problem on SO, but I've tried every search term that I think might apply.  However, I may not be using the correct search terms so forgive me if this is a duplicate, and please point me in the correct direction.  I have data that is grouped by sample and each sample has one value for each category, of which there are many.  Here is an example dataframe (note that the number of samples and number of categories are usually different):</p>
  
  <pre><code>df &lt;- data.frame( sample = c( "one", "two", "three", "four" ), 
    cat_1 = c( 2, 4, -6, 2 ), cat_2 = c( 1, 2, 2, 1 ), 
    cat_3 = c( 5, -5, 7, 2 ) ) 
  </code></pre>
  
  <p>I'm trying to create a plot where the x-axis has discrete points for each category, the y-axis is the value for all samples at each category, and those values for each sample across the categories are connected by lines of a color I can define.  </p>
  
  <p>It seems like <code>ggplot2</code> is the way to go here, but I can't find a way to get this to work out the way I want.  It seems like I want <code>colnames( dd )</code> to be the x-axis variable when using <code>aes()</code> but that warns me that <code>x</code> and <code>y</code> are not the same length.  Seems like this should be quite simple to do, but I can't figure it out.  </p>
  
  <p>EDIT:  I've come across this post <a href="https://stackoverflow.com/questions/37688887/plotting-multiple-variables-from-same-data-frame-in-ggplot">Plotting multiple variables from same data frame in ggplot</a> where the answer shows the exact type of plot I want to make, but I can't figure out how to use <code>melt</code> to change the my data frame into a format that puts the column names, <code>cat_1</code>, <code>cat_2</code>, <code>cat_3</code>, as the <code>id.vars</code>.  </p>