knitr::opts_chunk$set( collapse = TRUE, fig.retina = 2 )
waffle is a package to make waffle charts (square pie charts)
It uses ggplot2 and returns a ggplot2 object.
The following functions are implemented:
waffle
: make a waffle chart ggplot2 objectiron
: vertically stitch together multiple waffle plots, left-aligning edges (best if used with the waffle
pad
parameter)0.6.0
- keep factor levels; improve default aesthetics0.5.1
released - even moar improved ggplot2 compatibility0.5
released - new & improved ggplot2 compatibility0.4
released - added use_glyph
and glyph_size
to waffle
so you can now make isotype pictograms0.3
released - added a pad
parameter to waffle
to make it easier to align plots; added iron
to make it easier to do the alignment0.2.3
released - nulled many margins and made the use of coord_equal
optional via the equal
parameter0.2.1
released - added Travis tests to ensure independent package build confirmation0.2
released - added as_rcdimple
thx to Kent Russell (only in non-CRAN version)0.1
releasedinstall.packages("waffle")
options(width=120)
library(waffle) # current verison packageVersion("waffle") # basic example parts <- c(80, 30, 20, 10)
waffle(parts, rows=8)
# slightly more complex example parts <- c(`Un-breached\nUS Population`=(318-11-79), `Premera`=11, `Anthem`=79)
waffle(parts, rows=8, size=1, colors=c("#969696", "#1879bf", "#009bda")) + theme(legend.position="bottom")
Health records breaches as fraction of US Population
waffle(parts, rows=8, size=1, colors=c("#969696", "#1879bf", "#009bda")) + theme(legend.position="bottom")
One square == 1m ppl
waffle(parts/10, rows=3, colors=c("#969696", "#1879bf", "#009bda"))
Health records breaches as fraction of US Population
waffle(parts/10, rows=3, colors=c("#969696", "#1879bf", "#009bda"))
(One square == 10m ppl)
library(extrafont) waffle(parts/10, rows=3, colors=c("#969696", "#1879bf", "#009bda"), use_glyph="medkit", size=8)
library(extrafont) waffle(parts/10, rows=3, colors=c("#969696", "#1879bf", "#009bda"), use_glyph="medkit", glyph_size=8)
# replicating an old favourite # http://graphics8.nytimes.com/images/2008/07/20/business/20debtgraphic.jpg # http://www.nytimes.com/2008/07/20/business/20debt.html savings <- c(`Mortgage\n($84,911)`=84911, `Auto and\ntuition loans\n($14,414)`=14414, `Home equity loans\n($10,062)`=10062, `Credit Cards\n($8,565)`=8565)
waffle(savings/392, rows=7, size=0.5, colors=c("#c7d4b6", "#a3aabd", "#a0d0de", "#97b5cf")) + theme(legend.position="bottom")
Average Household Savings Each Year
waffle(savings/392, rows=7, size=0.5, colors=c("#c7d4b6", "#a3aabd", "#a0d0de", "#97b5cf")) + theme(legend.position="bottom")
(1 square == $392)
# similar to but not exact # https://eagereyes.org/techniques/square-pie-charts professional <- c(`Male`=44, `Female (56%)`=56)
waffle(professional, rows=10, size=0.5, colors=c("#af9139", "#544616"))
gridExtra::grid.arrange( waffle(c(thing1=0, thing2=100), rows=5), waffle(c(thing1=25, thing2=75), rows=5) )
Professional Workforce Makeup
waffle(professional, rows=10, size=0.5, colors=c("#af9139", "#544616"))
Iron example (left-align & padding for multiple plots)
pain.adult.1997 <- c( `YOY (406)`=406, `Adult (24)`=24) A <- waffle(pain.adult.1997/2, rows=7, size=0.5, colors=c("#c7d4b6", "#a3aabd"), title="Paine Run Brook Trout Abundance (1997)", xlab="1 square = 2 fish", pad=3) pine.adult.1997 <- c( `YOY (221)`=221, `Adult (143)`=143) B <- waffle(pine.adult.1997/2, rows=7, size=0.5, colors=c("#c7d4b6", "#a3aabd"), title="Piney River Brook Trout Abundance (1997)", xlab="1 square = 2 fish", pad=8) stan.adult.1997 <- c( `YOY (270)`=270, `Adult (197)`=197) C <- waffle(stan.adult.1997/2, rows=7, size=0.5, colors=c("#c7d4b6", "#a3aabd"), title="Staunton River Trout Abundance (1997)", xlab="1 square = 2 fish") iron(A, B, C)
library(waffle) library(testthat) date() test_dir("tests/")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.