if (require("ggplot2")) {
df <- data.frame(level = c("a", "b", "c", "d"),
outcome = c(2.3, 1.9, 3.2, 1))
# discrete 'brewer' palette
gg <- ggplot(df) +
geom_col_pattern(
aes(level, outcome, pattern_fill = level),
pattern = 'stripe',
fill = 'white',
colour = 'black'
) +
theme_bw(18) +
scale_pattern_fill_brewer()
plot(gg)
# continuous 'distiller' palette
gg <- ggplot(df) +
geom_col_pattern(
aes(level, outcome, pattern_fill = outcome),
pattern = 'stripe',
fill = 'white',
colour = 'black'
) +
theme_bw(18) +
scale_pattern_fill_distiller()
plot(gg)
}
Run the code above in your browser using DataLab