How can I pin the same color to a value in diffent plots?
Say I have two data.frames df1 and df2:
library(ggplot2) library(gridExtra) set.seed(1) d
To make this kind of composite plots, ggplot2 has facets:
ggplot2
df1$id = 'A' df2$id = 'B' df_all = rbind(df1, df2) ggplot(df_all, aes(x=x, y=y, fill=c)) + geom_bar(stat="identity") + facet_wrap(~id)
When using facets, ggplot2 treats both plots as one whole, keeping the color-value mapping the same.