title: Manually scale color, shape, and linetype of multiple geoms ggplot2
body: <p>A partial solution to my problem is found <a href="https://stackoverflow.com/questions/33236495/combine-legend-in-ggplot2">here</a>. I will show how that solution works and what features are still lacking to meet my needs.  For consistency, I use a sample data set that is similar to the one from the other thread:</p>
  
  <pre><code>library(ggplot2)
  library(reshape2)
  library(tidyverse)
  
  df &lt;- data.frame(x = c(1:5), a = c(1,2,3,3,3), b = c(1,1.1,1.3,1.5,1.5))
  df &lt;- mutate(df, log2 = log2(x))
  df &lt;- df &lt;- melt(df, c("x", "log2"))
  </code></pre>
  
  <p>An initial plot of the data (created by the following code) has the <code>shape</code> and <code>color</code> aesthetics in separate legends, which is undesirable:</p>
  
  <pre><code>ggplot(df) +
    geom_point(aes(x, value, colour = variable, shape = variable), size = 3) +
    geom_line(aes(x, log2, color = "log2(x)"), size = 1.5)
  </code></pre>
  
  <p>The solution proposes using <code>guides()</code> and <code>override.aes</code> to combine these into a single legend, which is certainly an improvement over the original plot:</p>
  
  <pre><code>ggplot(df) +
    geom_point(aes(x, value, colour = variable, shape = variable), size = 3) +
    geom_line(aes(x, log2, color = "log2(x)"), size = 1.5) +
    guides(shape = FALSE,
           colour = guide_legend(override.aes = list(shape = c(16, 17, NA),
                                                     linetype = c("blank", "blank", "solid"))))
  </code></pre>
  
  <p>My issue is that I would like manual control of the <code>color</code> aesthetic in  both <code>geom_point</code> and <code>geom_line</code>.  For example, I want to make the triangles light grey, the circles dark grey, and the <code>log2(x)</code> line light blue. My understanding of how <code>guides()</code> works is very limited, so the best I have been able to do is the following:</p>
  
  <pre><code>ggplot(df) +
    geom_point(aes(x, value, shape = variable), color = "gray40", size = 3, data = filter(df, variable == "a")) +
    geom_point(aes(x, value, shape = variable), color = "gray70", size = 3, data = filter(df, variable == "b")) +
    geom_line(aes(x, log2, shape = "log2(x)"), color = "cadetblue2", size = 1.5) +
    guides(shape = guide_legend(override.aes = list(color = c("gray40", "gray70", "cadetblue2"),
                                                    shape = c(16, 17, NA),
                                                    linetype = c("blank", "blank", "solid"))))
  </code></pre>
  
  <p>This seems like an improper use of the <code>shape</code> aesthetic in <code>geom_line</code> (given the warning generated), however it is <em>almost</em> the result I want.  The problem now is that the legend icon for <code>log2(x)</code> is missing.  Ideally it should show a horizontal light blue line that matches the plot.  Does anyone know how to achieve this and/or could better explain how the <code>guides()</code> function is intended to be used?  </p>
  
  <p>I have also tried solutions using a combination of <code>scale_color_manual()</code>, <code>scale_linetype_manual()</code>, and <code>scale_shape_manual()</code> (all with the same <code>name</code> argument that way they should end up in a single legend).  The issue with this approach has been that all 3 geom layers have a <code>color</code> aesthetic, but only the first two have a <code>shape</code> aesthetic and only the last one has a <code>linetype</code> aesthetic.  So even if all of the <code>scale_xx_manual()</code> additions to <code>ggplot</code> are set up correctly, the legends are not combined into a single one.</p>
  
  <p>I have been stuck on this for a long time, so any help would be greatly appreciated. Thank you</p>