placeholder - Filling with an image placeholder

Array-based patterns allow the user to specify an RGBA that should be displayed in the geom.

Getting the correct sized image such that it takes up the full space without being distorted can be a time-consuming task.

The placeholder pattern takes out this drudgery by fetching exactly the correct sized image to fit the space. These images come from image placeholder sites which are most often used by web-developers as a stand-in for a final image while they are developing a new site.

placeholder options

Aesthetic Description Default
pattern_type Image source ‘kitten’
pattern_alpha Alpha NA
pattern_aspect_ratio Override aspect ratio NA
pattern_key_scale_factor Additional scale factor for legend 1

placeholder option pattern_type

The following is a list of all the pattern_type values which are valid. If unspecified or unknown, then ggpattern will use pattern_type = 'kitten'.

If you would like only greyscale images, append bw to the name, e.g. to display only black and white kittens use pattern_type = 'kittenbw'.

Click the link to see an example of each placeholder generator

All placeholder names are available in ggpattern::placeholder_names.

Example Data

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Simple testing data
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
df1 <- data.frame(
  trt     = c("a", "b", "c"), 
  outcome = c(2.3, 1.9, 3.2),
  stringsAsFactors = FALSE
)

Example: pattern = 'placeholder' - pattern_type = 'bear'


ggplot(df1, aes(trt, outcome)) +
  geom_col_pattern(
    aes(fill = trt), 
    pattern      = 'placeholder', 
    pattern_type = 'bear',
    colour       = 'black'
  ) +
  theme_bw(15) +
  labs(
    title    = "ggpattern::geom_col_pattern()",
    subtitle = "pattern='placeholder', pattern_type='bear'"
  ) +
  theme(legend.position = 'none') +
  coord_fixed(ratio = 1/2)

Example: pattern = 'placeholder' - pattern_type = 'bear' with pattern_alpha

ggplot(df1, aes(trt, outcome)) +
  geom_col_pattern(
    aes(fill = trt), 
    pattern       = 'placeholder', 
    pattern_type  = 'bear',
    pattern_alpha = 0.5,
    colour        = 'black'
  ) +
  theme_bw(15) +
  labs(
    title    = "ggpattern::geom_col_pattern()",
    subtitle = "pattern='placeholder', pattern_type='bear'"
  ) +
  theme(legend.key.size = unit(1.5, 'cm')) +
  coord_fixed(ratio = 1/2)

Example: pattern = 'placeholder' - pattern_type = 'picsum'

ggplot(mtcars) +
  geom_density_pattern(
    aes(x = mpg, group = as.factor(cyl)),
    pattern      = 'placeholder',
    pattern_type = 'picsum'
  ) +
  theme_bw(15) +
  theme(legend.position = 'none') +
  labs(
    title    = "ggpattern::geom_col_pattern()",
    subtitle = "pattern='placeholder', pattern_type='picsum'"
  ) +
  coord_fixed(ratio = 80)

Example: pattern = 'placeholder' - pattern_type = 'dummy'

ggplot(df1, aes(trt, outcome)) +
  geom_col_pattern(
    aes(fill = trt), 
    pattern       = 'placeholder', 
    pattern_type  = 'dummy',
    colour        = 'black'
  ) +
  theme_bw(15) +
  labs(
    title    = "ggpattern::geom_col_pattern()",
    subtitle = "pattern='placeholder', pattern_type='dummy'"
  ) +
  theme(legend.position = 'none') +
  coord_fixed(ratio = 1/2)

Example: pattern = 'placeholder' - pattern_type = 'kitten'

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Example data for pie chart
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
df2 <- data.frame(
  group = factor(c("Cool", "But", "Use", "Less"), levels = c("Cool", "But", "Use", "Less")),
  value = c(10, 20, 30, 40)
)

ggplot(df2, aes(x="", y = value, pattern_angle = group))+
  geom_bar_pattern(
    pattern      = 'placeholder',
    pattern_type = 'kitten',
    pattern_aspect_ratio = 1,
    width        = 1,
    stat         = "identity",
    colour       = 'white',
    size         = 2
  ) +
  coord_polar("y", start=0) +
  theme_void(15) +
  theme(legend.position = 'none') +
  labs(
    title    = "ggpattern::geom_col_pattern()",
    subtitle = "pattern='placeholder', pattern_type='kitten'"
  )