Manually set scale of scale_fill_distiller()
<p>I am trying to make a series of plots for comparison. Say for example, I wanted to use the <code>iris</code> data set to make a plot like this where I have filtered to view only the setosa species:</p>

<pre><code>library(ggplot2)
library(dplyr)

iris %&gt;%
  filter(Species=="setosa") %&gt;%
  ggplot(aes(y = Sepal.Width, x = Sepal.Length, fill = Petal.Length)) +
  geom_tile(stat = "identity") +
  scale_fill_distiller(palette = "Spectral")
</code></pre>

<p><a href="https://i.stack.imgur.com/ZfUWH.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ZfUWH.png" alt="enter image description here"></a></p>

<p>Now if I want to plot the versicolor species in the same way I can do it like this:</p>

<pre><code>iris %&gt;%
  filter(Species=="versicolor") %&gt;%
  ggplot(aes(y = Sepal.Width, x = Sepal.Length, fill = Petal.Length)) +
  geom_tile(stat = "identity") +
  scale_fill_distiller(palette = "Spectral")
</code></pre>

<p><a href="https://i.stack.imgur.com/w2yOP.png" rel="noreferrer"><img src="https://i.stack.imgur.com/w2yOP.png" alt="enter image description here"></a></p>

<p>My issue is that the fill scales are different for these plot. I know I could <code>facet_wrap</code> these to solve this but let's just say I need individual plots. What I would like is to apply the same fill scale to both plots. Ideally I'd like to keep using <code>scale_fill_distiller</code> but I wasn't able to get very far as the values argument is a bit different for that function, so I tried <code>scale_fill_gradientn</code>. First I established a <code>fill_range</code> like so:</p>

<pre><code>fill_range &lt;- seq(min(iris$Petal.Length), max(iris$Petal.Length), by=0.2)
</code></pre>

<p>Then I tried inputting the seq into the values argument in <code>scale_fill_gradientn</code> like this:</p>

<pre><code>iris %&gt;%
  filter(Species=="versicolor") %&gt;%
  ggplot(aes(y = Sepal.Width, x = Sepal.Length, fill = Petal.Length)) +
  geom_tile(stat = "identity") +
  scale_fill_gradientn(colours = terrain.colors(length(fill_range)),
                         values=fill_range)

iris %&gt;%
  filter(Species=="setosa") %&gt;%
  ggplot(aes(y = Sepal.Width, x = Sepal.Length, fill = Petal.Length)) +
  geom_tile(stat = "identity")  +
  scale_fill_gradientn(colours = terrain.colors(length(fill_range)),
                       values=fill_range)
</code></pre>

<p>Neither of these produced a desired result, plotting a bunch of grey tiles and each with one green one. </p>

<p>Does anyone have an idea where I can manually specify the scale for <code>scale_fill_distiller"? If that is not possible, can anyone see where I have gone wrong with</code>scale_fill_gradientn`?</p>