Skip to contents

Draws a hand-drawn treemap: nested rectangles tiling a square, each with area proportional to a value, so the biggest categories take the most space. Map the value to area and the category to fill; map label to write a name in each tile. The rectangles are laid out with a squarified algorithm (treemap_layout()) and drawn with the roughened rect look, so they take any fill_style (including "watercolor"). Add ggplot2::coord_equal() for true proportions. No new dependencies (cf. treemapify::geom_treemap()).

Usage

StatSketchTreemap

GeomSketchTreemap

geom_sketch_treemap(
  mapping = NULL,
  data = NULL,
  stat = "sketch_treemap",
  position = "identity",
  ...,
  label_size = 3.2,
  label_colour = "grey15",
  colour = "grey25",
  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 area; usually map fill and optionally label.

data

Data to display.

stat

Statistical transformation. Default "sketch_treemap".

position

Position adjustment. Default "identity".

...

Other arguments passed on to the layer.

label_size

Label text size (as in ggplot2::geom_text()). Default 3.2.

label_colour

Label colour. Default "grey15".

colour

Tile outline colour. Default "grey25" (set NA for none).

fill_style

Tile 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("Alpha", "Bravo", "Charlie", "Delta", "Echo"),
                 val = c(40, 25, 15, 12, 8))
ggplot(df, aes(area = val, fill = grp, label = grp)) +
  geom_sketch_treemap(seed = 1L) +
  coord_equal() +
  theme_sketch()