title: Stacked Histogram in R ggplot with 100+ qualitative colors
body: <p>The data frame has many continuous numeric columns (e.g. <code>gr</code>) and a sample identifier - <code>wellseq</code>. There are many rows of data for each <code>wellseq</code>. In a data frame - there are 94 distinct levels of <code>wellseq</code> in 10227 rows. Header lines from data frame are:</p>
  
  <pre><code> gr wellseq
   1 27.7049       1
   2 31.1149       1
   3 34.5249       1
   4 39.7249       1
   5 44.9249       1
   6 50.1299       1
  </code></pre>
  
  <p>Summary of column <code>gr</code> is as below:</p>
  
  <pre><code>summary(GR)
         gr            
   Min.   :-6.94     
   1st Qu.:10.71   
   Median :13.76   
   Mean   :18.99   
   3rd Qu.:20.70   
   Max.   :98.42   
   NA's   :55
  </code></pre>
  
  <p>Basic Histogram of the entire data for the <code>gr</code> is suitably created. For further analysis, it is required to identify each <code>wellseq</code> contributing in the histogram. The <code>ggplot()</code> script used is:</p>
  
  <pre><code>p2 &lt;- ggplot() + theme_bw() + 
          geom_histogram(data=GR, na.rm= TRUE, mapping = aes(x=gr, fill=factor(GR$wellseq)), 
             bins = 10) + scale_color_brewer(palette = "Dark2") +
          scale_x_continuous(limits = c(-10, 100)) +
          labs(title=paste("Gamma Ray","Histogram", sep=" ")) +
          theme(legend.position = "none")
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/Uujhs.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Uujhs.jpg" alt="Sequential Color in Histogram"></a>
  The resulting output has color - which is "sequential" and NOT the "qualitative" palette "Dark2".  I tried using the answer in "How to generate a number of most distinctive colors in R?" @ stackoverflow.com and created required colors.</p>
  
  <pre><code>Dcolor = grDevices::colors()[grep('gr(a|e)y', grDevices::colors(), invert = T)]
  DcolorR &lt;- sample(Dcolor, 433, replace = F)
  </code></pre>
  
  <p>using <code>scale_colour_manual(values = DcolorR)</code></p>
  
  <p>gives the same histogram. Using <code>..count..</code> for <code>y</code> the histogram does show the boundaries for different <code>wellseq</code> but does not fill as needed. </p>
  
  <pre><code>p3 &lt;- ggplot() + theme_bw() +
      geom_histogram(data=GR, na.rm= TRUE, mapping = aes(x=gr, y= ..count.., col = factor(GR$wellseq), bins = 10)) +
      scale_colour_manual(values = DcolorR) +
      scale_x_continuous(limits = c(-10, 100)) +
      labs(title=paste("Gamma Ray"," Frequency Histogram", sep=" ")) +
      theme(legend.position = "none")
  fill = 1 # leads to blue colored staked histogram
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/fgrQI.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fgrQI.jpg" alt="..count.. creates discrete boundaries in the bars. Fill is single color"></a>
  I am trying to get a plot like attached. Please guide. Thanks in advance.</p>
  
  <p><a href="https://i.stack.imgur.com/hEpXL.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hEpXL.jpg" alt="Desired Output"></a></p>