How to make one common color guide for all the gradient plots in R ggplot?

75 Views Asked by At

I am making several gradient plots and then using grid to make a combined figure like below: enter image description here

The code to create one such plot is following:

plt<-ggplot(data=flat_df3,aes(y=Var2,x=Var1))+
  geom_tile(aes(fill=Value))+
  scale_fill_gradientn(colours = c(
    '#1E90FF','white','#DC143C'
    ),
                       limit=c(-10,10),
                       name=expression(paste(Delta,'T',' (sec)'))
                       )+
  theme_bw()+
  theme(axis.title = element_blank(),
        axis.text = element_blank(),
        axis.ticks = element_blank()
        )+
  coord_fixed()

As a consequence, for each plot I am having a color guide on the right, which does not look good to me. I am looking for a method by which I can make a single common color guide (since they have the same scale) say on the right side of the plot. How to achieve this?

1

There are 1 best solutions below

0
BEVAN On

You could combine all your data using bind_rows or similar, and then facet_wrap() based on the variable that is different between the data sets.