Demo: Rendering Images in Polygons with {ggplot2} and {ggpattern}

After seeing a wonderful plot by darwinanddavis on twitter, I was reminded that I need to address some bugs in {ggpattern}.

Instead I made a plot with kittens as the texture for a map of Australia.

A worthwhile diversion!

library(dplyr)
library(ggplot2)
# remotes::install_github("coolbutuseless/ggpattern")
library(ggpattern)

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Fetch the map data as a data.frame
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
oz_df <- ggplot2::map_data('world', 'australia') 
mainland_df <- oz_df %>% filter(
  is.na(subregion)
)

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Render the whole of australia (including islands) as a polygon 
# Render mainland australia with kittens
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ggplot() + 
  geom_polygon(data = oz_df, mapping = aes(long, lat, group = group)) + 
  geom_polygon_pattern(data = mainland_df, mapping = aes(long, lat, group = group), 
                       pattern = 'placeholder', pattern_type = 'kitten') + 
  coord_equal() + 
  theme_bw() + 
  labs(
    title = "ggpattern::geom_polygon_pattern(..., pattern = 'placeholder')",
    subtitle = "pattern_type = 'kitten'"
  )