gradient options

Aesthetic Description Default
pattern_fill First colour ‘grey80’
pattern_fill2 Second colour ‘#4169E1’
pattern_orientation vertical, horizontal or radial ‘vertical’
pattern_alpha Alpha 1
pattern_aspect_ratio Override aspect ratio NA
pattern_key_scale_factor Additional scale factor for legend 1

Example Data

df <- data.frame(
  trt         = c("a", "b", "c"), 
  outcome     = c(2.3, 1.9, 3.2)
)

Example: pattern_type = 'gradient' - Fade to white

ggplot(df, aes(trt, outcome)) +
  geom_col_pattern(
    aes(
      pattern_fill        = trt,
      pattern_orientation = trt
    ), 
    pattern       = 'gradient', 
    pattern_fill2 = 'white', 
    colour        = 'black'
  ) +
  theme_bw(15) +
  labs(
    title    = "ggpattern::geom_col_pattern()",
    subtitle = "pattern = 'gradient'"
  ) +
  theme(
    legend.key.size = unit(1.5, 'cm')
  ) +
  coord_fixed(ratio = 1/2) 

Example: pattern_type = 'gradient' - Fade to dark blue

ggplot(df, aes(trt, outcome)) +
  geom_col_pattern(
    aes(
      pattern_fill        = trt,
      pattern_orientation = trt
    ), 
    pattern       = 'gradient', 
    pattern_fill2 = '#445566', 
    colour        = 'black'
  ) +
  theme_bw(15) +
  labs(
    title    = "ggpattern::geom_col_pattern()",
    subtitle = "pattern = 'gradient'"
  ) +
  theme(
    legend.key.size = unit(1.5, 'cm')
  ) +
  coord_fixed(ratio = 1/2)

Example: pattern_type = 'gradient' - Fade to transparent

ggplot(df, aes(trt, outcome)) +
  geom_col_pattern(
    aes(
      pattern_fill        = trt,
      pattern_orientation = trt
    ), 
    pattern       = 'gradient', 
    pattern_fill2 = NA, 
    fill          = NA,
    colour        = 'black'
  ) +
  theme_bw(15) +
  labs(
    title    = "ggpattern::geom_col_pattern()",
    subtitle = "pattern = 'gradient'"
  ) +
  theme(legend.key.size = unit(1.5, 'cm')) +
  coord_fixed(ratio = 1/2)

Example: pattern_type = 'gradient' - Non-rectangular geom

ggplot(mtcars) +
  geom_density_pattern(
    aes(
      x = mpg, 
      pattern_fill = as.factor(cyl),
      pattern_orientation = as.factor(cyl)
    ), 
    pattern       = 'gradient',
    pattern_fill2 = NA, 
    fill          = NA
  ) +
  theme_bw(15) +
  labs(
    title    = "ggpattern::geom_density_pattern()",
    subtitle = "pattern = 'gradient'"
  ) +
  theme(legend.key.size = unit(1.5, 'cm')) +
  coord_fixed(ratio = 80)