title: recreate scale_fill_brewer with scale_fill_manual
body: <p>I am trying to understand the connection between <code>scale_fill_brewer</code> and <code>scale_fill_manual</code> of package <code>ggplot2</code>. </p>
  
  <p>First, generate a ggplot with filled colors:</p>
  
  <pre><code>library(ggplot2)
  p &lt;- ggplot(data = mtcars, aes(x = mpg, y = wt, 
      group = cyl, fill = factor(cyl))) + 
      geom_area(position = 'stack')
  
  # apply ready-made palette with scale_fill_brewer from ggplot2
  p + scale_fill_brewer(palette = "Blues")
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/kzdZC.png" alt="enter image description here"></p>
  
  <p>Now, replicate with <code>scale_fill_manual</code></p>
  
  <pre><code>library(RColorBrewer)
  p + scale_fill_manual(values = brewer.pal(3, "Blues"))  
  </code></pre>
  
  <p>where 3 is the number of fill-colors in the data. For convenience, I have used the <code>brewer.pal</code> function of package <code>RColorBrewer</code>.</p>
  
  <p>As far as I understand, the convenience of <code>scale_fill_brewer</code> is that it automatically computes the number of unique levels in the data (3 in this example). Here is my attempt at replicating:</p>
  
  <pre><code>p + scale_fill_manual(values = brewer.pal(length(levels(factor(mtcars$cyl))), "Blues"))
  </code></pre>
  
  <p><strong>My question is: how does <code>scale_fill_brewer</code> compute the number of levels in the data?</strong> </p>
  
  <p>I'm interested in understanding what else <code>fill_color_brewer</code> might be doing under the hood. Might I run into any difficulty if I replace the more user friendly <code>fill_color_brewer</code> with a more contorted implementation of <code>scale_fill_manual</code> like the one above.</p>
  
  <p>Perusing the source code:</p>
  
  <pre><code>scale_fill_brewer
  function (..., type = "seq", palette = 1) {
      discrete_scale("fill", "brewer", brewer_pal(type, palette), ...)
  }
  </code></pre>
  
  <p>I couldn't see through this how <code>scale_fill_brewer</code> computes the number of unique levels in the data. Perhaps hidden in the <code>...</code> ?</p>
  
  <p><strong>Edit: Where does the function <code>scale_fill_brewer</code> receive instructions to compute the number of levels in the data? Is it in <code>"seq"</code> or in <code>...</code> or elsewhere?</strong></p>
  
  <p>The <code>discrete_scale</code> function is intricate and I'm lost. Here are its arguments:</p>
  
  <pre><code>discrete_scale &lt;- function(aesthetics, scale_name, palette, name = NULL, 
      breaks = waiver(), labels = waiver(), legend = NULL, limits = NULL, 
      expand = waiver(), na.value = NA, drop = TRUE, guide="legend") {
  </code></pre>
  
  <p>Does any of this compute the number of levels?</p>