title: Manual fill geom_tile with multiple scales by group
body: <p>I have the following current output: <a href="https://i.stack.imgur.com/QfmjP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QfmjP.png" alt=""></a></p>
  
  <p>And I am aiming for a colouring like this, but only filled until the maximum level (e.g the fill stops at the level present):</p>
  
  <p><a href="https://i.stack.imgur.com/5YXbs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5YXbs.png" alt=""></a></p>
  
  <p>The data to create this, is:</p>
  
  <pre><code>df &lt;- tribble(~Question_Code,   ~RespondentLevel,
  "Engagement - Inclusion",   5,
  "External engagement - policies",   2,
  "External engagement - technology", 5,
  "Community data ",  5,
  "Internal engagement",  5,
  "Internal use of technology",   4,
  "Familiarity/Alignment",    5,
  "Environmental impacts",    5,
  "Innovation",   2,
  "Use of open-source technology",    2,
  "Regulation of hardware &amp; software",    5,
  "In-house technical capacity",  5,
  "Infrastructure procurement",   5,
  "Algorithmic Error &amp; Bias", 2,
  "Control: Privacy", 5,
  "Accountability in Governance Structures",  3,
  "Open procurement", 5,
  "Use in decision-making",   1,
  "Accountability",   1,
  "External Control", 4,
  "Internal Control", 2,
  "Open Data",    2)
  levels &lt;-  c("Open Data","Internal Control","External Control","Accountability",
               "Use in decision-making","Open procurement","Accountability in Governance Structures","Control: Privacy",
               "Algorithmic Error &amp; Bias","Infrastructure procurement","In-house technical capacity",
               "Regulation of hardware &amp; software","Use of open-source technology","Innovation",
               "Environmental impacts","Familiarity/Alignment",
               "Internal use of technology","Internal engagement","Community data",
               "External engagement - technology","External engagement - policies","Engagement - Inclusion")
  
  df &lt;- df %&gt;% mutate(Domain = c(as.character((rep("Domain 1", 5))),
                    as.character(rep("Domain 2", 4)),
                    as.character(rep("Domain 3", 6)),
                    as.character(rep("Domain 4", 7))))
  
  </code></pre>
  
  <p>And for the ggplot:</p>
  
  <pre><code>df %&gt;% 
  ggplot(aes(x = RespondentLevel, y = fct_rev(Question_Code))) +
    geom_tile() +
    theme_minimal(16)
  
  </code></pre>
  
  <p>The colours to fill, I'm using:</p>
  
  <pre><code>with each colour corresponding to a domain, and each shade to a level:
  Greens &lt;- c("#edf8e9", "#bae4b3", "#74c476", "#31a354", "#006d2c")
  
  Reds &lt;- c("#fee5d9", "#fcae91", "#fb6a4a", "#de2d26", "#a50f15")
  
  Yellows &lt;- c("#ffffeb","#ffff9d","#ffff89", "#ffff4e", "#ffff14")
  
  Blues &lt;- c("#eff3ff","#bdd7e7","#6baed6","#3182bd",  "#08519c")
  
  </code></pre>
  
  <p>EDIT: geom_bar also does the trick, but not broken down by gradient. Trying to use <a href="https://stackoverflow.com/questions/49818271/stacked-barplot-with-colour-gradients-for-each-bar">this function</a>:</p>
  
  <pre><code>ColourPalleteMulti &lt;- function(df, group, subgroup){
  
    # Find how many colour categories to create and the number of colours in each
    categories &lt;- aggregate(as.formula(paste(subgroup, group, sep="~" )), df, function(x) length(unique(x)))
    category.start &lt;- (scales::hue_pal(l = 100)(nrow(categories))) # Set the top of the colour pallete
    category.end  &lt;- (scales::hue_pal(l = 40)(nrow(categories))) # set the bottom
  
    # Build Colour pallette
    colours &lt;- unlist(lapply(1:nrow(categories),
                             function(i){
                               colorRampPalette(colors = c(category.start[i], category.end[i]))(categories[i,2])}))
    return(colours)
  }
  
  colours &lt;- ColourPalleteMulti(df, "Domain", "RespondentLevel") 
  </code></pre>
  
  <pre><code>df %&gt;% 
    ggplot(aes(x = fct_rev(Question_Code), y = RespondentLevel))+
    geom_bar(stat = "identity", aes(fill = Domain), alpha = .9) +
    coord_flip() +
    theme_minimal(16)+
    xlab(" ") +
    ggtitle("Baseline Report Card Sample Community")+
    scale_fill_manual("RespondentLevel", values = colours)+
    theme(legend.title = element_text(size = 14),
          legend.position = "none",
          legend.text = element_text(size = 14),
          plot.title = element_text(size=18, hjust = 0.5),
          plot.caption = element_text(size = 12, hjust = 1),
          axis.text.y = element_text(hjust = 0),
          panel.grid = element_line(colour = "#F0F0F0"),
          plot.margin = unit(c(1,1,0.5,1), "cm"))
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/AUeCr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AUeCr.png" alt="enter image description here"></a></p>
  
  <p>Sorry for the long reprex, can adjust if possible</p>