title: Mapping a different factor to the legend labels in R ggplot
body: <p>I want to give additional information in my legend. I want to give each graph a unique color using an ID. But my legend labels I want to contain information from a factor that can be equal for different IDs but is always constant for one ID.
  Example:</p>
  <pre><code>mydata &lt;- data.frame(x=rep(1:10,5),
  y=rep((1:10),5)*sort(rep((10:14)/10,10)),
  ID=sort(rep(1:5,10)),
  info1=sort(rep(c(&quot;A&quot;,&quot;B&quot;,&quot;C&quot;,&quot;D&quot;,&quot;C&quot;),10)),
  info2=sort(rep(c(&quot;GG&quot;,&quot;HH&quot;,&quot;HH&quot;,&quot;GG&quot;,&quot;II&quot;),10)))
  
  ggplot(mydata,aes(x=x,y=y,color=as.factor(ID)))+geom_line()
  </code></pre>
  <p>This gives me the plot as it should be plus a legend showing the IDs.</p>
  <p><a href="https://i.stack.imgur.com/fQf5L.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fQf5L.png" alt="enter image description here" /></a></p>
  <p>Now my question ist how to replace the IDs by the factors in info1 while keeping distinct colors for each graph. And even better would be to include information from info1 and info2 in one legend...</p>
  <p>I know how to use an additional invisibe plot to get additional legends, but this is not quite what I want:</p>
  <pre><code>ggplot(mydata,aes(x=x,y=y,color=as.factor(ID)))+geom_line() +
  geom_point(aes(shape=NA,size=info1,fill=info2)) + guides(color=FALSE)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/HbQxz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HbQxz.png" alt="enter image description here" /></a></p>
  <p>Instead, I would like the legend like in the first picture, but the information (label) from the second picture. Of course, taking the information from the data.frame only, not giving it explicitly.</p>
  <p>Thank you for suggestions</p>