Hair colour and eye colour
Column widths show the shares of hair colours. Within each column, compare the eye-colour shares by height. With zero gaps, tile area equals the cell's share of the whole table.

PNG · SVG · PDF · Download R script · Software versions
View R code
library(ggplot2)
library(ggforma)
counts <- marginSums(HairEyeColor, c("Hair", "Eye"))
ggmosaic(counts, shade = "category", category = "Eye", gap = 0, labeling = "border", label = NULL) +
labs(title = "Hair and eye colour", subtitle = "Area is proportional to the observed count")Reproduce all three exports
# Run in the folder containing the downloaded mosaic-2d.R script.
draw_example <- function(ext) {
path <- paste0('mosaic-2d.', ext)
switch(ext,
png = ragg::agg_png(path, width = 7.5, height = 4.35, units = 'in', res = 144, background = 'white'),
svg = grDevices::svg(path, width = 7.5, height = 4.35, bg = 'white'),
pdf = grDevices::cairo_pdf(path, width = 7.5, height = 4.35, bg = 'white')
)
on.exit(grDevices::dev.off())
source('mosaic-2d.R', local = new.env(), echo = FALSE, print.eval = TRUE, encoding = 'UTF-8')
}
invisible(lapply(c('png', 'svg', 'pdf'), draw_example))




















