title: Plotting a line per row of a dataframe, at given x-values, using ggplot2
body: <p>Using <code>matplot</code>, I can plot a line for each row of a dataframe at given <em>x</em> values. For example </p>
  
  <pre><code>set.seed(1)
  df &lt;- matrix(runif(20, 0, 1), nrow = 5)
  
  matplot(t(df), type = "l", x = c(1, 3, 7, 9)) # c(1, 3, 7, 9) are the x-axis positions I'd like to plot along
  # the line colours are not important
  </code></pre>
  
  <p>I'd like to use <code>ggplot2</code> instead, but I'm not sure how best to replicate the outcome. Using <code>melt</code> I can rename the columns to the desired x values, as below. But is there a 'cleaner' approach that I'm missing?</p>
  
  <pre><code>df1 &lt;- as.data.frame(df)
  names(df1) &lt;- c(1, 3, 7, 9) # rename columns to the desired x-axis values
  df1$id &lt;- 1:nrow(df1)
  df1_melt &lt;- melt(df1, id.var = "id")
  df1_melt$variable &lt;- as.numeric(as.character(df1_melt$variable)) # convert x-axis values from factor to numeric
  
  ggplot(df1_melt, aes(x = variable, y = value)) + geom_line(aes(group = id))
  </code></pre>
  
  <p>Any help would be much appreciated. Thanks</p>