Mosaic Plots in the 'ggplot2' Framework

Mosaic plots in the 'ggplot2' framework. Mosaic plot functionality is provided in a single 'ggplot2' layer by calling the geom 'mosaic'.

CRANStatus CRAN RStudio mirrordownloads Travis-CI BuildStatus

ggmosaic was designed to create visualizations of categorical data and is capable of producing bar charts, stacked bar charts, mosaic plots, and double decker plots.


You can install ggmosaic from github with:

# install.packages("devtools")


#> Loading required package: ggplot2
ggplot(data = fly) +
  geom_mosaic(aes(x = product(RudeToRecline), fill=DoYouRecline))

geom_mosaic: setting the aesthetics

Aesthetics that can be set:

  • weight : select a weighting variable
  • x : select variables to add to formula
    • declared as x = product(x1, x2, …)
  • fill : select a variable to be filled
    • if the variable is not also called in x, it will be added to the formula in the first position
  • conds : select a variable to condition on
    • declared as conds = product(cond1, cond2, …)

These values are then sent through productplots functions to create the formula for the desired distribution

Formula: weight ~ fill + x | conds

From the aesthetics to the formula

Example of how the formula is built

  • weight = 1
  • x = product(Y, X)
  • fill = W
  • conds = product(Z)

These aesthetics set up the formula for the distribution: 1 ~ W + X + Y | Z

Because a mosaic plot is constructed hierarchically through alternating spines, the ordering of the variables is very important.


ggmosaic 0.2.0

Small Usage Changes

  • fixed bugs in previous versions

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


0.2.0 by Haley Jeppson, 5 months ago

Report a bug at

Browse source code at

Authors: Haley Jeppson [aut, cre] , Heike Hofmann [aut] , Di Cook [aut] , Hadley Wickham [ctb]

Documentation:   PDF Manual  

GPL (>= 2) license

Imports dplyr, plotly, productplots, purrr, rlang, tidyr

Depends on ggplot2

Suggests gridExtra, knitr, NHANES, rmarkdown

See at CRAN