Mosaic plots in the 'ggplot2' framework. Mosaic plot functionality is provided in a single 'ggplot2' layer by calling the geom 'mosaic'.
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")devtools::install_github("haleyjeppson/ggmosaic")
library(ggmosaic)#> Loading required package: ggplot2ggplot(data = fly) +geom_mosaic(aes(x = product(RudeToRecline), fill=DoYouRecline))
Aesthetics that can be set:
These values are then sent through productplots
functions to create
the formula for the desired distribution
Formula: weight ~ fill + x | conds
Example of how the formula is built
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.