true
library(tidyverse)
devtools::install_github("hrbrmstr/waffle")
## extrafont   (NA -> 0.17 ) [CRAN]
## extrafontdb (NA -> 1.0  ) [CRAN]
## Rttf2pt1    (NA -> 1.3.8) [CRAN]
##   
   checking for file ‘/tmp/RtmpVWEM1I/remotes20d1167774ef/hrbrmstr-waffle-3f61463/DESCRIPTION’ ...
  
✔  checking for file ‘/tmp/RtmpVWEM1I/remotes20d1167774ef/hrbrmstr-waffle-3f61463/DESCRIPTION’
## 
  
─  preparing ‘waffle’:
## 
  
   checking DESCRIPTION meta-information ...
  
✔  checking DESCRIPTION meta-information
## 
  
─  checking for LF line-endings in source and make files and shell scripts
## 
  
─  checking for empty or unneeded directories
## 
  
─  building ‘waffle_1.0.1.tar.gz’
## 
  
   
## 
devtools::install_github("hrbrmstr/hrbrthemes")
## gdtools     (NA   -> 0.2.2) [CRAN]
## tinytex     (0.21 -> 0.22 ) [CRAN]
## systemfonts (NA   -> 0.2.0) [CRAN]
##   
   checking for file ‘/tmp/RtmpVWEM1I/remotes20d1650beccc/hrbrmstr-hrbrthemes-a599f17/DESCRIPTION’ ...
  
✔  checking for file ‘/tmp/RtmpVWEM1I/remotes20d1650beccc/hrbrmstr-hrbrthemes-a599f17/DESCRIPTION’
## 
  
─  preparing ‘hrbrthemes’:
## 
  
   checking DESCRIPTION meta-information ...
  
✔  checking DESCRIPTION meta-information
## 
  
─  checking for LF line-endings in source and make files and shell scripts
## 
  
─  checking for empty or unneeded directories
## 
  
─  building ‘hrbrthemes_0.8.0.tar.gz’
## 
  
   
## 
library(hrbrthemes)
library(waffle)

Neat examples for waffle plots.

commute_mode <-
  readr::read_csv(
    "https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2019/2019-11-05/commute.csv"
  )

Fix some entries

commute_mode$state_region[commute_mode$state == "Ca"] <- "West"
commute_mode$state_region[commute_mode$state == "Massachusett"] <- "Northeast"
commute_mode$state_abb[commute_mode$state == "Ca"] <- "CA"
commute_mode$state_abb[commute_mode$state == "Massachusett"] <- "MA"
commute_mode$state[commute_mode$state == "Ca"] <- "California"
commute_mode$state[commute_mode$state == "Massachusett"] <- "Massachusetts"

commute_mode$state_region[commute_mode$state == "District of Columbia"] <- "Northeast"
commute_mode$state_abb[commute_mode$state == "District of Columbia"] <- "D.C."

Aggregate by state and make a waffle with facet?

by_state <- 
  commute_mode %>% 
  group_by(state_region, state, state_abb, mode) %>% 
  summarise_at(.vars = vars("n"), .funs = list("sum"))

# should be empty
by_state %>% filter(is.na(state_region))
## # A tibble: 0 x 5
## # Groups:   state_region, state, state_abb [0]
## # … with 5 variables: state_region <chr>, state <chr>, state_abb <chr>,
## #   mode <chr>, n <dbl>
by_state %>% filter(state_abb == "CA") %>%
  ggplot(data = ., aes(
    fill = mode,
    values = n / 1000
  )) +
  geom_waffle(n_rows = 10, colour="white") +
  scale_fill_manual(
    name = NULL,
    values = c("#a40000", "#c68958"),
    labels = c("Bike", "Walk")
  ) +
  coord_equal() +
  theme_ipsum_rc(grid="") +
  theme_enhance_waffle()

if (FALSE) {
  # difficult to plot and facet 50 
(
  state_waffle <-
    ggplot(data = by_state, aes(fill = mode, values = n/5000)) +
    geom_waffle(n_rows = 20, size=.5, colour="white", flip = TRUE) +
    scale_fill_manual(
      name = NULL,
      values = c("#a40000", "#c68958"),
      labels = c("Bike", "Walk")
    ) +
    coord_equal() +
    theme_minimal() +
    theme_enhance_waffle() +
    facet_wrap("state_abb")
)

#ggsave(state_waffle, filename = "2019-11-05/state_waffle.pdf")
}

Aggregate by region instead

by_region <- 
  commute_mode %>% 
  group_by(state_region, mode) %>% 
  summarise_at(.vars = vars("n"), .funs = list("sum"))

if (TRUE) {
  (
    state_waffle <-
      ggplot(data = by_region, aes(fill = mode, values = n/5000)) +
      geom_waffle(n_rows = 20, size=.5, colour="white", flip = TRUE) +
      scale_fill_manual(
        name = NULL,
        values = c("#a40000", "#c68958"),
        labels = c("Bike", "Walk")
      ) +
      coord_equal() +
      theme_minimal() +
      theme_enhance_waffle() +
      facet_wrap("state_region")
  )
  
  #ggsave(state_waffle, filename = "2019-11-05/region_waffle.pdf")
}