Make square pie charts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
boB Rudis 08684ef6cc
Merge pull request #44 from amrrs/patch-1
6 years ago
R Fix for #42 and enabled use of any user font 6 years ago
README_files README 6 years ago
inst Fix for #42 and enabled use of any user font 6 years ago
man Fix for #42 and enabled use of any user font 6 years ago
tests travis tests 9 years ago
.Rbuildignore CRAN Fixes 6 years ago
.gitignore initial commit 9 years ago
.travis.yml for travis 7 years ago
CONDUCT.md Fix for #42 and enabled use of any user font 6 years ago
DESCRIPTION CRAN Fixes 6 years ago
NAMESPACE Fix for #42 and enabled use of any user font 6 years ago
NEWS.md CRAN Fixes 6 years ago
README.Rmd code snipped close - fa_list 6 years ago
README.md README 6 years ago
cran-comments.md for travis 7 years ago
waffle.Rproj docs & cleanup after CHECK 9 years ago

README.md

BuildStatus CRAN\_Status\_Badge downloads

waffle

Create Waffle Chart Visualizations

Description

Square pie charts (a.k.a. waffle charts) can be used to communicate parts of a whole for categorical quantities. To emulate the percentage view of a pie chart, a 10x10 grid should be used with each square representing 1% of the total. Modern uses of waffle charts do not necessarily adhere to this rule and can be created with a grid of any rectangular shape. Best practices suggest keeping the number of categories small, just as should be done when creating pie charts. Tools are provided to create waffle charts as well as stitch them together, and to use glyphs for making isotype pictograms.

It uses ggplot2 and returns a ggplot2 object.

The following functions are implemented:

  • waffle : make a waffle chart ggplot2 object
  • iron : vertically stitch together multiple waffle plots, left-aligning edges (best if used with the waffle pad parameter)
  • fa_grep: Search FontAwesome names for a pattern
  • `fa_list: List all FontAwesome names

Installation

install.packages("waffle")

Usage

library(waffle)

# current verison
packageVersion("waffle")
## [1] '0.9.0'

Basic example

parts <- c(80, 30, 20, 10)
waffle(parts, rows = 8)

Use a data frame

parts <- data.frame(
  names = LETTERS[1:4],
  vals = 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"), legend_pos = "bottom"
)

Health records breaches as fraction of US Population

One square == 1m ppl

waffle(
  parts / 10, rows = 3,
  colors = c("#969696", "#1879bf", "#009bda")
)

Health records breaches as fraction of US Population

(One square == 10m ppl)

library(extrafont)

waffle(
  parts / 10, rows = 3, colors = c("#969696", "#1879bf", "#009bda"),
  use_glyph = "medkit", size = 8
)

Replicating an old favourite

Via: https://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, legend_pos = "bottom",
  colors = c("#c7d4b6", "#a3aabd", "#a0d0de", "#97b5cf")
)

Average Household Savings Each Year

(1 square == $392)

More replication

Similar to 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")
)

Keeps factor by default levels now

With:

iron(
  waffle(c(thing1 = 0, thing2 = 100), rows = 5),
  waffle(c(thing1 = 25, thing2 = 75), rows = 5)
)

Without (you can disable this via keep parameter now):

iron(
  waffle(c(thing1 = 0, thing2 = 100), rows = 5, keep = FALSE),
  waffle(c(thing1 = 25, thing2 = 75), rows = 5, keep = FALSE)
)

Professional Workforce Makeup

Iron example (left-align & padding for multiple plots)

pain.adult.1997 <- c(`YOY (406)` = 406, `Adult (24)` = 24)

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
) -> A

pine.adult.1997 <- c(`YOY (221)` = 221, `Adult (143)` = 143)

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
) -> B

stan.adult.1997 <- c(`YOY (270)` = 270, `Adult (197)` = 197)

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"
) -> C

iron(A, B, C)

Code of Conduct

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.