title: How to build a Heatmap for each facet with its own respective scale instead of just one generic scale for all in r?
body: <p>I am trying to create a <code>heatmap</code> that should <strong>assign colors</strong> based on <code>% vaccinated</code> <strong>for each month</strong> (for each row)</p>
  <p>for example Comparison by colors between all states in month of Jan, then</p>
  <p>for example Comparison by colors between all states in month of March .. .</p>
  <p>then Apr ... Jun etc</p>
  <p><strong>Issue:</strong> Basically I would like <strong>Each month to have its own high &amp; low scale</strong> &amp; I am trying to do that with <code>facet</code> but it is assigning one common low-high scale for all the facets/months.</p>
  <pre><code>library(tidyverse)
  library(lubridate)
  library(scales)
  
  file_url1 &lt;- url(&quot;https://raw.githubusercontent.com/johnsnow09/covid19-df_stack-code/main/df_vaccination.csv&quot;)
  
  df_vaccination &lt;- read.csv(url(file_url1))
  
  df_vaccination &lt;- df_vaccination %&gt;%
    mutate(Updated.On = as.Date(Updated.On))
  </code></pre>
  <p><strong>Code:</strong> I have tried</p>
  <pre><code>df_vaccination %&gt;% 
    filter(State != &quot;India&quot;) %&gt;% 
  
    # summarise each month, state's vaccination
    mutate(month_abbr = month(Updated.On, label = TRUE, abbr = TRUE),
           State = fct_reorder(State, Population, max)) %&gt;% 
    group_by(month_abbr, State) %&gt;% 
    summarise(monthly_ind_vaccinated = sum(Total.Individuals.Vaccinated_Dailycalc, 
                                        na.rm = TRUE),
              Population = first(Population), .groups = &quot;drop&quot;) %&gt;% 
    
    # get % Vaccination to State population for each month
    group_by(State) %&gt;% 
    mutate(prc_vaccinated_per_pop = monthly_ind_vaccinated / Population) %&gt;% 
    na.omit() %&gt;%
    ungroup() %&gt;% 
  
    filter(State %in% c(&quot;Delhi&quot;,&quot;Maharashtra&quot;)) %&gt;%
    
    # group_by(month_abbr) %&gt;%
    
    ggplot(aes(x = State, y = month_abbr, fill = prc_vaccinated_per_pop)) +
    geom_tile() +
    
    scale_fill_gradient2(low = &quot;white&quot;, high = &quot;darkblue&quot;, labels = percent) +
      
    facet_wrap(~as.factor(month_abbr), scales = &quot;free_y&quot;, nrow = 6) +
    
    theme(axis.text.x = element_text(angle = 90, vjust = -.02),
          strip.text = element_blank()) +
    labs(title = &quot;States with highest % Vaccination each month ?&quot;,
         caption = &quot;created by ViSa&quot;,
         fill = &quot;% Vaccinated each month&quot;,
         x = &quot;&quot;, y = &quot;&quot;)
  </code></pre>
  <p><strong>output:</strong></p>
  <p><a href="https://i.stack.imgur.com/ntgTR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ntgTR.png" alt="enter image description here" /></a></p>
  <p>I think since the color value is based on <code>fill</code> so it is not letting different scales apply on different facets.</p>
  <p>Is there anything like <strong>(scales = <code>free_fill</code>)</strong> instead of <strong>(scales = <code>free_y</code>)</strong> ?</p>
  <p>data output:</p>
  <pre><code># A tibble: 12 x 5
  # Groups:   month_abbr [6]
     month_abbr State     monthly_ind_vaccina~ Population prc_vaccinated_per_~
     &lt;ord&gt;      &lt;fct&gt;                    &lt;int&gt;      &lt;dbl&gt;                &lt;dbl&gt;
   1 Jan        Delhi                    43948   18710922              0.00235
   2 Jan        Maharash~               228424  123144223              0.00185
   3 Feb        Delhi                   322859   18710922              0.0173 
   4 Feb        Maharash~               794370  123144223              0.00645
   5 Mar        Delhi                   666628   18710922              0.0356 
   6 Mar        Maharash~              4590035  123144223              0.0373 
   7 Apr        Delhi                  1547324   18710922              0.0827 
   8 Apr        Maharash~              7942882  123144223              0.0645 
   9 May        Delhi                  1613335   18710922              0.0862 
  10 May        Maharash~              4455440  123144223              0.0362 
  11 Jun        Delhi                   250366   18710922              0.0134 
  12 Jun        Maharash~              1777873  123144223              0.0144 
  </code></pre>