I am trying to make two plots. One shows the boxplots for variable x split by factor category1 and the second plot is the same, but for variable y.
I have provided reproducible code below.
require(ggplot2)
dataset <- data.frame(category1 = rep(LETTERS[1:5], 100),
y = rnorm(500, mean = rep(1:5, 100)),
z = rnorm(500, mean = rep(c(1:4,NA), 100)))
ggplot(dataset, aes(x=factor(category1), y=y, fill=category1)) + geom_boxplot()
ggplot(dataset, aes(x=factor(category1), y=z, fill=category1)) + geom_boxplot()
The plots are fine, except that I want the colors to carry through, i.e. so that the color for A in category1 is always the same shade of red. I know that ggplot is coloring based on the color wheel divided by 5, and then by 4, respectively, but I don't know how to make it always divide by 5 and use the same color consistently, even though there is no value E in factor z, in the second plot.