waffle | R Documentation |
A waffle chart.
waffle(
mat,
xpad = 0,
ypad = 0,
heights = NULL,
widths = NULL,
colpad = 0,
rowpad = 0,
invert = "",
...,
reset_par = TRUE,
add = FALSE
)
mat |
a matrix of integers or character strings of color names; if
|
xpad , ypad |
padding between |
heights , widths |
row heights and column widths, respectively, usually
in |
colpad , rowpad |
amount of padding between columns and rows; note that
these shift the |
invert |
character string indicating about which axis the matrix
should be inverted; possible values are |
... |
additional graphical parameters passed to |
reset_par |
logical; if |
add |
logical; use |
A list of four matrices:
$matrix |
the input matrix as plotted including inversions |
$origin |
coordinates of the bottom-left corner for each box |
$centers |
coordinates for the centers of each box |
$rect |
coordinates for each corner of each box |
waffle(matrix(1:9, 3))
waffle(matrix(1:9, 3), invert = 'x')
waffle(matrix(1:9, 3), heights = c(.25, .95, .5), border = NA)
waffle(matrix(1:9, 3), xpad = 0, colpad = c(0, .1, 0))
## heatmap
## convert the numeric data to color strings
cols <- c(cor(mtcars))
cols <- tcol(c('blue', 'red')[(cols > 0) + 1L], alpha = c(abs(cols)))
mat <- matrix(cols, 11)
waffle(mat, reset_par = FALSE, invert = 'x')
axis(3, at = 1:11 - .5, labels = names(mtcars), lwd = 0)
## use colpad/rowpad to create sections
w <- waffle(mat, reset_par = FALSE, invert = 'x',
colpad = rep(c(0, 0.5, 1, 0), c(5, 1, 1, 4)),
rowpad = rep(c(0, 0.5, 0), c(5, 1, 5)))
axis(3, unique(w$centers[, 'x']), names(mtcars), lwd = 0)
## adding to margins of another plot
set.seed(1)
n <- 97
ng <- 3
cols <- c('beige', 'dodgerblue2', 'green', 'orange')
x <- sample(cols, n * ng, replace = TRUE, prob = c(.05,.31,.32,.32))
x <- kinda_sort(x, n = 20)
op <- par(fig = c(0, 1, 0.2, 0.9), mar = c(0, 5, 0, 1))
plot(cumsum(rnorm(n)), type = 'l', ann = FALSE, xaxt = 'n')
par(fig = c(0, 1, 0, 0.2), mar = c(1, 5, 0, 1), new = TRUE)
waffle(matrix(x, ng), heights = c(0.95, 0.5, 0.95), border = 'white',
reset_par = FALSE) -> wf
text(0, rev(unique(wf$centers[, 'y'])), paste('Feature', 1:3),
xpd = NA, pos = 2L)
par(fig = c(0, 1, 0.9, 1), mar = c(0.5, 5, 0.5, 1), new = TRUE)
waffle(matrix(x, ng)[1L, , drop = FALSE], heights = 0.5,
border = 'white', reset_par = FALSE)
box()
box('outer')
par(op)
## waffle conveniently returns the centers of the rects
## be sure _not_ to reset pars for proper alignment
w <- waffle(matrix(1:8, 2), reset_par = FALSE, invert = 'xy')
text(w$c[, 'x'], w$c[, 'y'], labels = palette(), col = 'white')
## this is similar to ?rawr::show_colors
col <- colors()[1:25 ^ 2]
w <- waffle(matrix(col, 25), reset_par = FALSE, invert = 'xy', border = NA)
text(w$c[, 'x'], w$c[, 'y'], labels = col, col = 'black', cex = .4)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.