title: Nested categorical variables as aesthetics
body: <p>Say I have a dataset where I have a categorical variable where the categories are of two different fundamental types: for instance, that one of them represents the total of the values from the other two categories.  I can encode this by a separate categorical variable, say <code>is_total</code>.</p>
  <pre class="lang-r prettyprint-override"><code>library(tidyverse)
  
  dat &lt;- tribble(
    ~x, ~y, ~categorical, ~is_total,
     0,  0,          &quot;A&quot;,     FALSE,
     1,  1,          &quot;A&quot;,     FALSE,
     0,  1,          &quot;B&quot;,     FALSE,
     1,  3,          &quot;B&quot;,     FALSE,
     0,  1,      &quot;Total&quot;,      TRUE,
     1,  4,      &quot;Total&quot;,      TRUE
  )
  </code></pre>
  <p>I then want to create a line plot, where the total is shown with one type of line and the two components are shown with another type of line, and all three lines have different colours.  I can do that like this:</p>
  <pre class="lang-r prettyprint-override"><code>ggplot(dat, aes(x, y, colour = categorical, linetype = is_total)) +
    geom_line()
  </code></pre>
  <p>The problem is that I don't want two legends: I want &quot;Total&quot; to be shown with a dashed line in the second legend (and then I can get rid of the legend for <code>is_total</code> using <code>guides(linetype = FALSE)</code>).  How would I do that?  (I hoped changing the titles to be the same using <code>labs</code> would make it work things out, but sadly not.)</p>