I am plotting several matrices in ggplot using geom_tile(). I'm using colors to represent the value variable (i.e. the fill). All data are in one dataframe. I am trying to get the range of colors in the fill to be scaled uniquely for each element/marix of the plot. Using facet_wrap() currently, it finds the highest value across all plots and assigns that as the 'high' value. Likewise it finds the lowest value for the 'low' value.
I've tried using scales='free' in the facet_wrap() but that isn't logical (and doesn't work). Essentially I want it to assign the high and low values for the fill based on the highest and lowest value within each group. I don't want to make every plot individually as I have dozens of plots.
Here is some sample data:
library(ggplot2) set.seed(110)
dfA <- data.frame(Var1=rep(LETTERS[1:5],5), Var2=rep(LETTERS[1:5],each=5), Value=sample(1:30, replace=T, 25), Group="A")
dfB <- data.frame(Var1=rep(LETTERS[1:5],5), Var2=rep(LETTERS[1:5],each=5), Value=sample(15:60, replace=T, 25), Group="B")
dfC <- data.frame(Var1=rep(LETTERS[1:5],5), Var2=rep(LETTERS[1:5],each=5), Value=sample(1:99, replace=T, 25), Group="C")
dfX <- rbind(dfA,dfB,dfC)
Here I plot three tiled plots using facet_wrap() :
ggplot(dfX, aes(Var1, Var2, fill = Value)) +
geom_tile(colour="white", size=1.75, stat="identity") +
scale_fill_gradient(low = "white", high = "red") +
geom_text(data=dfX, aes(Var1, Var2, label = Value), color="black", size=rel(5)) +
facet_wrap(~Group)
The above plot is not ideal as the first two matrices should have the same fill scale as the final matrix even though their number distributions are lower in range. Ideally, I'd like a solution that isn't just ranging the data for each group between 0-1 e.g using the formula zi=xi−min(x) / max(x)−min(x)

