I'm having some difficulties with color mapping in ggplot2. Two out of the four plots have the same six county variables. However, the "Carbon Monoxide" and "Coarse Particulate matter" subplots only have five (Pierce County is missing).
Each pollutant has a different unit on the y-axis, and labeling individual facets in a single ggplot is a challenge. To get around this, I am generating each plot individually then grouping them together using gridExtra
.
Is it possible to apply the same color mapping from the three plots with sixe counties to the carbon monoxide plot?
Here's an example of how I'm making an individual plot:
library(ggplot2)
library(dplyr)
library(gridExtra)
p1 <- ggplot(filter(df, pollutant == "Nitrogen dioxide"), aes(x = as.factor(season), y = value, fill = as.factor(county))) +
geom_boxplot(position = "dodge")
## I'm excluding a bunch of code to format the font and size of the title/legend/axis labels
g <- grid.extra(p1, p2, p3, p4)