title: R - Writing a generic function that will colour different lines in a ggplot line graph based on the parameters
body: <p>I found the title difficult to word but essentially I want to be able to colour different lines of the plot based on parameters passed to a function call. I can't provide my data but the following code will generate a data frame in the same shape and style as mine. It will also generate the base plot for what I'm trying to accomplish.</p>
  
  <pre><code>a = c(1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4,5,5,5,5,5)
  b = c("a", "b", "c", "d", "e", "a", "b", "c", "d", "e", "a", "b", "c", "d", "e", "a", "b", "c", "d", "e", "a", "b", "c", "d", "e")
  c = sample(1:100, 25, replace = TRUE)
  df = data.frame(a,b,c)
  ggplot(df, aes(x = a, y = c, group = b, colour = b))+
      geom_line(linetype = "dashed", size = 1, colour = "grey")
  </code></pre>
  
  <p>Essentially I'd like to be able to pass to the function a vector containing say the values "a", "b", "e" and then the plot will change. The "a", "b", and "e" lines will now be in colour and there will be a legend on the side with the name and colour of the line. </p>
  
  <p>I've tried a few methods, the closest to being successful was adding the lines in a for loop, but I couldn't get the legend to work and all the lines came in the same colour. </p>
  
  <p>I realize this question is probably a duplicate but I've been searching to no avail for a couple days so even being pointed to an answered question may be helpful.
  Thanks!</p>