Closed trevorld closed 3 years ago
library("ggpattern") library("ggplot2", warn.conflicts = FALSE) library("gridpattern") # remotes::install_github("trevorld/gridpattern") crosshatch2_pattern <- function(params, boundary_df, aspect_ratio, legend) { args <- as.list(params) args <- args[grep("^pattern_", names(args))] args$pattern <- "crosshatch" args$x <- boundary_df$x args$y <- boundary_df$y args$id <- boundary_df$id args$prefix <- "" do.call(gridpattern::patternGrob, args) } options(ggpattern_geometry_funcs = list(crosshatch2 = crosshatch2_pattern)) df <- data.frame(trt = c("a", "b", "c"), outcome = c(2.3, 1.9, 3.2), pattern = c("stripe", "stripe", "crosshatch2"), pattern_angle = c(30, -60, 30), pattern_fill = c("grey40", "white", "grey40"), pattern_fill2 = c(NA, NA, "white")) ggplot(df, aes(trt, outcome)) + geom_col_pattern(aes(fill = trt), pattern = df$pattern, pattern_angle = df$pattern_angle, pattern_fill = df$pattern_fill, pattern_fill2 = df$pattern_fill2, colour = 'black')