| Title: | Waffle Style Chart with a Brick Layout in 'ggplot2' |
|---|---|
| Description: | A new take on the bar chart. Similar to a waffle style chart but instead of squares the layout resembles a brick wall. |
| Authors: | Daniel Oehm [aut, cre] |
| Maintainer: | Daniel Oehm <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.3.2 |
| Built: | 2026-06-05 07:18:59 UTC |
| Source: | https://github.com/doehm/ggbrick |
Brick row
brick_row( layer, bpl, brick_height = 1, brick_width = 2.5, gap = 0.125, width = 0.9, .geom = "brick" )brick_row( layer, bpl, brick_height = 1, brick_width = 2.5, gap = 0.125, width = 0.9, .geom = "brick" )
layer |
Brick layer. |
bpl |
Number of bricks in the layer. |
brick_height |
Brick height. |
brick_width |
Brick width. |
gap |
Gap between the bricks. |
width |
Column width |
.geom |
Geom type for layering. Either 'brick' or 'brick_waffle' |
Build the wall
build_wall(n_bricks, height, bpl, gap = NULL, width = 0.9)build_wall(n_bricks, height, bpl, gap = NULL, width = 0.9)
n_bricks |
Number of bricks |
height |
Height of the wall. |
bpl |
Bricks per layer |
gap |
The space between bricks. |
width |
Column_width |
Build the wall
build_wall_waffle(n_bricks, height, bpl, gap = NULL, width = 0.9)build_wall_waffle(n_bricks, height, bpl, gap = NULL, width = 0.9)
n_bricks |
Number of bricks |
height |
Height of the wall. |
bpl |
Bricks per layer |
gap |
The space between bricks. |
width |
Column width. |
A fixed scale coordinate system forces a specified ratio similar to
coord_fixed. It holds the coordinates fixed at the right ratio
to ensure each brick is of the right dimensions.
coord_brick( bricks_per_layer = 4, ratio = NULL, xlim = NULL, ylim = NULL, expand = TRUE, clip = "on", width = 0.9 ) coord_waffle( bricks_per_layer = 4, ratio = NULL, xlim = NULL, ylim = NULL, expand = TRUE, clip = "on", width = 0.9 )coord_brick( bricks_per_layer = 4, ratio = NULL, xlim = NULL, ylim = NULL, expand = TRUE, clip = "on", width = 0.9 ) coord_waffle( bricks_per_layer = 4, ratio = NULL, xlim = NULL, ylim = NULL, expand = TRUE, clip = "on", width = 0.9 )
bricks_per_layer |
Number of bricks per layer. Should match the |
ratio |
aspect ratio, expressed as |
xlim, ylim
|
Limits for the x and y axes. |
expand |
If |
clip |
Should drawing be clipped to the extent of the plot panel? A
setting of |
width |
Column width. If using a different |
ggplot object
# ensures that the ranges of axes are equal to the specified ratio by library(ggplot2) library(dplyr) # create a base plot plt <- mpg %>% count(class, drv) %>% ggplot() + geom_brick(aes(class, n, fill = drv), bricks_per_layer = 6) # view the base plot plt # View the base plot with fixed coords # Ensure `bricks_per_layer` matches the geom plt %>% coord_brick(6) # The same using `geom_waffle` mpg %>% count(class, drv) %>% ggplot() + geom_waffle(aes(class, n, fill = drv), bricks_per_layer = 6) + coord_waffle(6)# ensures that the ranges of axes are equal to the specified ratio by library(ggplot2) library(dplyr) # create a base plot plt <- mpg %>% count(class, drv) %>% ggplot() + geom_brick(aes(class, n, fill = drv), bricks_per_layer = 6) # view the base plot plt # View the base plot with fixed coords # Ensure `bricks_per_layer` matches the geom plt %>% coord_brick(6) # The same using `geom_waffle` mpg %>% count(class, drv) %>% ggplot() + geom_waffle(aes(class, n, fill = drv), bricks_per_layer = 6) + coord_waffle(6)
GeomBrick
GeomBrickGeomBrick
An object of class GeomBrick (inherits from GeomRect, Geom, ggproto, gg) of length 6.
GeomBrick
GeomBrick0GeomBrick0
An object of class GeomBrick0 (inherits from GeomBrick, GeomRect, Geom, ggproto, gg) of length 6.
GeomBrick
GeomWaffleGeomWaffle
An object of class GeomWaffle (inherits from GeomRect, Geom, ggproto, gg) of length 6.
GeomBrick
GeomWaffle0GeomWaffle0
An object of class GeomWaffle0 (inherits from GeomWaffle, GeomRect, Geom, ggproto, gg) of length 6.
half brick row
half_brick_row( layer, bpl, brick_height = 1, brick_width = 2.5, gap = 0.125, width = 0.9 )half_brick_row( layer, bpl, brick_height = 1, brick_width = 2.5, gap = 0.125, width = 0.9 )
layer |
Brick layer. |
bpl |
Number of bricks in the layer. |
brick_height |
Brick height. |
brick_width |
Brick width. |
gap |
Gap between the bricks. |
width |
Column_width |
Makes the vector for the fill aesthetic
make_new_fill(fill, n, val)make_new_fill(fill, n, val)
fill |
The fill vector. |
n |
Vector representing the number of bricks for the fill level. |
val |
Vector of length the same as fill of with 1 o 0.5 for whole or half bricks. |
Ensures the half bricks are randomised in pairs to preserve the total
robust_random(x, val)robust_random(x, val)
x |
x. |
val |
Value. |
Robust round
robust_round(x, N)robust_round(x, N)
x |
Vector of values. |
N |
Value to preserve sum to. |
Creates a 'waffle' style chart with the aesthetic of a brick wall. Usage is
similar to geom_col where you supply counts as the height of the bar. Each
whole brick represents 1 unit. Two half bricks equal one whole brick. Where
the count exceeds the number of brick layers, the number of bricks is scaled
to retain the brick wall aesthetic.
stat_brick( mapping = NULL, data = NULL, geom = "rect", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, width = 0.9, bricks_per_layer = 4, type = "ordered", gap = NULL, ... ) geom_brick( mapping = NULL, data = NULL, stat = "brick", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, bricks_per_layer = 4, width = 0.9, type = "ordered", gap = NULL, ... ) geom_brick0( mapping = NULL, data = NULL, stat = "brick", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, bricks_per_layer = 4, type = "ordered", gap = 0, width = 0.9, ... )stat_brick( mapping = NULL, data = NULL, geom = "rect", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, width = 0.9, bricks_per_layer = 4, type = "ordered", gap = NULL, ... ) geom_brick( mapping = NULL, data = NULL, stat = "brick", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, bricks_per_layer = 4, width = 0.9, type = "ordered", gap = NULL, ... ) geom_brick0( mapping = NULL, data = NULL, stat = "brick", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, bricks_per_layer = 4, type = "ordered", gap = 0, width = 0.9, ... )
mapping |
Set of aesthetic mappings created by aes(). If specified and
|
data |
The data to be displayed in this layer. There are three options: If A A |
geom |
Geom |
position |
Position adjustment, either as a string naming the adjustment
(e.g. |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
width |
Column width. Default value is |
bricks_per_layer |
The number of bricks per layer. Default 4. |
type |
The type of fill ordering. one of 'ordered', 'random' or 'soft_random', Default 'ordered' |
gap |
The space between bricks. |
... |
Dots. |
stat |
The statistical transformation to use on the data for this
layer, either as a |
ggplot object
geom_brick() understands the following aesthetics (required aesthetics are in bold):
x
y
alpha
colour
fill
group
linetype
linewidth
library(ggplot2) library(dplyr) mpg %>% count(class, drv) %>% ggplot() + geom_brick(aes(class, n, fill = drv)) + coord_brick()library(ggplot2) library(dplyr) mpg %>% count(class, drv) %>% ggplot() + geom_brick(aes(class, n, fill = drv)) + coord_brick()
Creates a 'waffle' style chart with the aesthetic of a brick wall. Usage is
similar to geom_col where you supply counts as the height of the bar. Each
whole brick represents 1 unit. Two half bricks equal one whole brick. Where
the count exceeds the number of brick layers, the number of bricks is scaled
to retain the brick wall aesthetic.
stat_waffle( mapping = NULL, data = NULL, geom = "rect", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, bricks_per_layer = 4, type = "ordered", gap = NULL, width = 0.9, ... ) geom_waffle( mapping = NULL, data = NULL, stat = "waffle", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, bricks_per_layer = 4, type = "ordered", gap = NULL, width = 0.9, ... ) geom_waffle0( mapping = NULL, data = NULL, stat = "waffle", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, bricks_per_layer = 4, type = "ordered", gap = 0, width = 0.9, ... )stat_waffle( mapping = NULL, data = NULL, geom = "rect", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, bricks_per_layer = 4, type = "ordered", gap = NULL, width = 0.9, ... ) geom_waffle( mapping = NULL, data = NULL, stat = "waffle", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, bricks_per_layer = 4, type = "ordered", gap = NULL, width = 0.9, ... ) geom_waffle0( mapping = NULL, data = NULL, stat = "waffle", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, bricks_per_layer = 4, type = "ordered", gap = 0, width = 0.9, ... )
mapping |
Set of aesthetic mappings created by aes(). If specified and
|
data |
The data to be displayed in this layer. There are three options: If A A |
geom |
Geom |
position |
Position adjustment, either as a string naming the adjustment
(e.g. |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
bricks_per_layer |
The number of bricks per layer. Default 4. |
type |
The type of fill ordering. one of 'ordered', 'random' or 'soft_random', Default 'ordered' |
gap |
The space between bricks. |
width |
Column width. Default |
... |
Dots. |
stat |
The statistical transformation to use on the data for this
layer, either as a |
ggplot object
geom_waffle() understands the following aesthetics (required aesthetics are in bold):
x
y
alpha
colour
fill
group
linetype
linewidth
library(ggplot2) library(dplyr) mpg %>% count(class, drv) %>% ggplot() + geom_waffle(aes(class, n, fill = drv)) + coord_waffle()library(ggplot2) library(dplyr) mpg %>% count(class, drv) %>% ggplot() + geom_waffle(aes(class, n, fill = drv)) + coord_waffle()
Switch position for soft random
switch_pos(x, n)switch_pos(x, n)
x |
Vector to switch values in. |
n |
Number to switch. |