I would like to set distinct patterns for my box and whisker plot variables.
I have tried using scale_pattern_manual() but it is not setting distinct patterns for each variable and is setting a stripe pattern to all variables.
DF2 <- data.frame(
x = c(c(A1, A2, A3), c(B1, B2, B3)),
y = rep(c("A", "B"), each = 15),
z = rep(rep(1:3, each=5), 2),
stringsAsFactors = FALSE
)
cols <- rainbow(3, s = 0.5)
boxplot(x ~ z + y, data = DF2,
at = c(1:3, 5:7), col = cols,
names = c("", "A", "", "", "B", ""), xaxs = FALSE)
library(ggplot2)
ggplot(DF2, aes(y, x, fill=factor(z))) +
geom_boxplot_pattern() + scale_pattern_manual(values = c("wave","stripe","crosshatch"))