Skip to contents

Draws a hand-drawn waffle: a square grid (default 10x10 = 100 cells) where each cell is coloured by category, so the number of cells of a colour reads as that category's share of the whole. Map the category to fill; map a count to weight if the data is already summarised (otherwise each row counts as one). Cells are drawn with geom_sketch_tile(), so they take the usual roughened outline and fill_style (including "watercolor"). Add ggplot2::coord_equal() to keep the cells square. (cf. waffle::geom_waffle()).

Usage

StatSketchWaffle

geom_sketch_waffle(
  mapping = NULL,
  data = NULL,
  stat = "sketch_waffle",
  position = "identity",
  ...,
  n_rows = 10L,
  cells = 100L,
  flip = FALSE,
  width = 0.9,
  height = 0.9,
  colour = "grey35",
  fill_style = "hachure",
  roughness = 1,
  bowing = 1,
  n_passes = 2L,
  seed = NULL,
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = TRUE
)

Arguments

mapping

Aesthetic mappings created by ggplot2::aes(). Requires fill; optionally weight (a per-row count).

data

Data to display.

stat

Statistical transformation. Default "sketch_waffle".

position

Position adjustment. Default "identity".

...

Other arguments passed on to the layer.

n_rows

Number of rows in the grid. Default 10.

cells

Total number of cells (the grid resolution). Default 100, i.e. a percentage waffle.

flip

Fill columns top-down instead of bottom-up? Default FALSE.

width, height

Cell size in grid units (gaps appear below 1). Default 0.9.

colour

Outline colour for each cell. Default "grey35".

fill_style

Cell fill style; see geom_sketch_rect(). Default "hachure".

roughness, bowing, n_passes, seed

Sketch parameters.

na.rm

Remove missing values silently? Default FALSE.

show.legend

Logical; include in legend?

inherit.aes

Override default aesthetics?

Value

A ggplot2 layer object.

Examples

library(ggplot2)
df <- data.frame(grp = c("Rent", "Food", "Travel", "Other"),
                 spend = c(45, 25, 20, 10))
ggplot(df, aes(fill = grp, weight = spend)) +
  geom_sketch_waffle(seed = 1L) +
  coord_equal() +
  theme_sketch()