Title: | 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. |
Authors: | Bob Rudis [aut, cre] , Dave Gandy [aut] (Font Awesome), Andrew Breza [ctb], Matthias Jütte [ctb], Paul Campbell [ctb] (geom_bar flip) |
Maintainer: | Bob Rudis <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.0.2 |
Built: | 2024-12-23 03:14:40 UTC |
Source: | https://github.com/hrbrmstr/waffle |
For glyphs:
Font Awesome by Dave Gandy - http://fontawesome.io
License: SIL OFL 1.1
URL: http://scripts.sil.org/OFL
Search Font Awesome glyph names for a pattern
fa_grep(pattern)
fa_grep(pattern)
pattern |
pattern to search for in the names of Font Awesome fonts |
'fa5_brand' is shorthand for "'FontAwesome5Brands-Regular'"
fa5_brand
fa5_brand
An object of class character
of length 1.
'fa5_solid' is shorthand for "'FontAwesome5Free-Solid'"
fa5_solid
fa5_solid
An object of class character
of length 1.
There are two special/critical aes()
mappings:
label
(so the geom knows which column to map the glyphs to)
values
(which column you're mapping the filling for the squares with)
geom_pictogram( mapping = NULL, data = NULL, n_rows = 10, make_proportional = FALSE, flip = FALSE, ..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) GeomPictogram
geom_pictogram( mapping = NULL, data = NULL, n_rows = 10, make_proportional = FALSE, flip = FALSE, ..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) GeomPictogram
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
n_rows |
how many rows should there be in the waffle chart? default is 10 |
make_proportional |
compute proportions from the raw values? (i.e. each
value |
flip |
If |
... |
other arguments passed on to |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
An object of class GeomPictogram
(inherits from GeomText
, Geom
, ggproto
, gg
) of length 5.
There are two special/critical aes()
mappings:
fill
(so the geom knows which column to map the fills to)
values
(which column you're mapping the filling for the squares with)
geom_waffle( mapping = NULL, data = NULL, n_rows = 10, make_proportional = FALSE, flip = FALSE, na.rm = FALSE, show.legend = NA, radius = grid::unit(0, "npc"), inherit.aes = TRUE, ... ) GeomWaffle stat_waffle( mapping = NULL, data = NULL, geom = "waffle", n_rows = 10, make_proportional = FALSE, flip = FALSE, radius = grid::unit(0, "npc"), na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ... ) StatWaffle
geom_waffle( mapping = NULL, data = NULL, n_rows = 10, make_proportional = FALSE, flip = FALSE, na.rm = FALSE, show.legend = NA, radius = grid::unit(0, "npc"), inherit.aes = TRUE, ... ) GeomWaffle stat_waffle( mapping = NULL, data = NULL, geom = "waffle", n_rows = 10, make_proportional = FALSE, flip = FALSE, radius = grid::unit(0, "npc"), na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ... ) StatWaffle
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
n_rows |
how many rows should there be in the waffle chart? default is 10 |
make_proportional |
compute proportions from the raw values? (i.e. each
value |
flip |
If |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
radius |
radius for round squares |
inherit.aes |
If |
... |
other arguments passed on to |
geom |
geom to use (default is "waffle") |
An object of class GeomWaffle
(inherits from GeomRtile
, GeomRrect
, Geom
, ggproto
, gg
) of length 5.
An object of class StatWaffle
(inherits from Stat
, ggproto
, gg
) of length 8.
data.frame( parts = factor(rep(month.abb[1:3], 3), levels=month.abb[1:3]), vals = c(10, 20, 30, 6, 14, 40, 30, 20, 10), fct = c(rep("Thing 1", 3), rep("Thing 2", 3), rep("Thing 3", 3)) ) -> xdf ggplot(xdf, aes(fill = parts, values = vals)) + geom_waffle() + facet_wrap(~fct)
data.frame( parts = factor(rep(month.abb[1:3], 3), levels=month.abb[1:3]), vals = c(10, 20, 30, 6, 14, 40, 30, 20, 10), fct = c(rep("Thing 1", 3), rep("Thing 2", 3), rep("Thing 3", 3)) ) -> xdf ggplot(xdf, aes(fill = parts, values = vals)) + geom_waffle() + facet_wrap(~fct)
Install Font Awesome 5 Fonts
install_fa_fonts()
install_fa_fonts()
Left-align the waffle plots by x-axis. Use the pad
parameter in
waffle
to pad each plot to the max width (num of squares), otherwise
the plots will be scaled.
iron(...)
iron(...)
... |
one or more waffle plots |
parts <- c(80, 30, 20, 10) w1 <- waffle(parts, rows=8) w2 <- waffle(parts, rows=8) w3 <- waffle(parts, rows=8) # print chart ## iron(w1, w2, w3)
parts <- c(80, 30, 20, 10) w1 <- waffle(parts, rows=8) w2 <- waffle(parts, rows=8) w3 <- waffle(parts, rows=8) # print chart ## iron(w1, w2, w3)
Used with geom_pictogram() to map Font Awesome fonts to labels
scale_label_pictogram(..., values, aesthetics = "label")
scale_label_pictogram(..., values, aesthetics = "label")
... |
dots |
values |
values |
aesthetics |
aesthetics |
Removes:
theme_enhance_waffle()
theme_enhance_waffle()
panel grid
all axis text
all axis ticks
all axis titles
Given a named vector or a data frame, this function will return a ggplot object that represents a waffle chart of the values. The individual values will be summed up and each that will be the total number of squares in the grid. You can perform appropriate value transformation ahead of time to get the desired waffle layout/effect.
waffle( parts, rows = 10, keep = TRUE, xlab = NULL, title = NULL, colors = NA, size = 2, flip = FALSE, reverse = FALSE, equal = TRUE, pad = 0, use_glyph = FALSE, glyph_size = 12, glyph_font = "Font Awesome 5 Free Solid", glyph_font_family = "FontAwesome5Free-Solid", legend_pos = "right" )
waffle( parts, rows = 10, keep = TRUE, xlab = NULL, title = NULL, colors = NA, size = 2, flip = FALSE, reverse = FALSE, equal = TRUE, pad = 0, use_glyph = FALSE, glyph_size = 12, glyph_font = "Font Awesome 5 Free Solid", glyph_font_family = "FontAwesome5Free-Solid", legend_pos = "right" )
parts |
named vector of values or a data frame to use for the chart |
rows |
number of rows of blocks |
keep |
keep factor levels (i.e. for consistent legends across waffle plots) |
xlab |
text for below the chart. Highly suggested this be used to give the "1 sq == xyz" relationship if it's not obvious |
title |
chart title |
colors |
exactly the number of colors as values in |
size |
width of the separator between blocks (defaults to |
flip |
flips x & y axes |
reverse |
reverses the order of the data |
equal |
by default, waffle uses |
pad |
how many blocks to right-pad the grid with |
use_glyph |
use specified glyph; if using built-in Font Awesome, can be the glyph name; otherwise, it must be the unicode glyph from the custom font the caller is using. |
glyph_size |
size of the Font Awesome font |
glyph_font , glyph_font_family
|
if |
legend_pos |
position of legend |
If a data frame is used, the first two columns should contain the desired names and the values, respectively.
If the vector is not named or only partially named, capital letters will be used instead.
It is highly suggested that you limit the number of elements to plot, just like you should if you ever got wasted and decided that a regular pie chart was a good thing to create and then decide to be totally evil and make one to pollute this beautiful world of ours.
Chart title and x-axis labels are optional, especially if you'll just be exporting to another program for use/display.
If you specify a string (vs FALSE
) to use_glyph
the function
will map the input to a Font Awesome glyph name and use that glyph for the
tile instead of a block (making it more like an isotype pictogram than a
waffle chart). You'll need to install Font Awesome 5 and use
the extrafont
package to
be able to use Font Awesome 5 glyphs. Sizing is also up to the user since
fonts do not automatically scale with graphic resize.
Glyph idea inspired by Ruben C. Arslan (@_r_c_a)
You MUST use the Font Awesome 5 fonts bundled with the package.
See install_fa_fonts()
.
parts <- c(80, 30, 20, 10) waffle(parts, rows=8) parts <- data.frame( names = LETTERS[1:4], vals = c(80, 30, 20, 10) ) waffle(parts, rows=8) # library(extrafont) # waffle(parts, rows=8, use_glyph="shield") parts <- c(One=80, Two=30, Three=20, Four=10) chart <- waffle(parts, rows=8) # print(chart)
parts <- c(80, 30, 20, 10) waffle(parts, rows=8) parts <- data.frame( names = LETTERS[1:4], vals = c(80, 30, 20, 10) ) waffle(parts, rows=8) # library(extrafont) # waffle(parts, rows=8, use_glyph="shield") parts <- c(One=80, Two=30, Three=20, Four=10) chart <- waffle(parts, rows=8) # print(chart)