| Title: | Icon Geometries for 'ggplot2' |
|---|---|
| Description: | Provides icon geometries for 'ggplot2', using vector icon sets from the 'icons' package. Icons can be drawn as points in place of ordinary markers, styled with the usual colour, size, alpha and angle aesthetics, and mapped from discrete values or passed through directly. Icons also appear in legend keys, as fixed-position annotations, and as axis, strip and legend labels. Pictograms extend this to isotype-style unit charts, waffle/percentage charts and rating widgets, encoding a value as a grid of repeated icons. |
| Authors: | Mitchell O'Hara-Wild [aut, cre] (ORCID: <https://orcid.org/0000-0001-6729-7695>) |
| Maintainer: | Mitchell O'Hara-Wild <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0.9000 |
| Built: | 2026-09-16 12:13:57 UTC |
| Source: | https://github.com/mitchelloharawild/ggicons |
annotation_icon() draws one or more icons at fixed (x, y) positions,
the icon analogue of ggplot2::annotation_custom() /
ggplot2::annotation_raster(): a single call that adds icons directly,
without a data frame or aes() mapping. Unlike those, though,
annotation_icon() does train the panel's position scales, since a
fixed-position icon is more usefully treated like a point annotation
(e.g. ggplot2::annotate()) than like an arbitrary grob pinned to the
panel's corners, so placing one outside the data's range still expands
the axes to fit it.
annotation_icon( icon, x, y, colour = "black", fill = NA, size = 6, alpha = NA, angle = 0, size.unit = "mm" )annotation_icon( icon, x, y, colour = "black", fill = NA, size = 6, alpha = NA, angle = 0, size.unit = "mm" )
icon |
An icon vector from the icons package. Character ids are not resolved; pass an actual icon vector. |
x, y
|
The position(s) to draw the icon(s) at, in data coordinates. |
colour, fill
|
Fill colour for the icon; |
size |
The icon's width/height, in |
alpha |
Transparency, from 0 (fully transparent) to 1 (opaque). |
angle |
Rotation, in degrees. |
size.unit |
The unit in which |
icon, x, y and the style arguments are all recycled to a common
length, so a single call can place several icons at once (e.g.
annotation_icon(icon = c(rocket, star), x = c(1, 2), y = c(1, 1))).
A ggplot2 layer.
annotation_icon() sets the same per-icon properties geom_icon()
understands as aesthetics, but as plain arguments instead:
icon (required): an icon vector from the
icons package, an icon
object (e.g. from icons::read_icon() or
icons::fontawesome$solid$rocket) or an icons::icon_find() result.
x, y: the position(s) to draw at, in data coordinates.
colour/fill: both map to the icon's single fill colour (icons
don't have a separate border); fill wins when both are set.
alpha
size: the icon's width/height, in size.unit (default millimetres).
angle: rotation, in degrees.
stroke/linewidth don't apply, since icons are filled shapes, not
framed ones.
library(ggplot2) # bundled placeholder shapes; a real pack (e.g. icons::fontawesome) works the same shapes <- icons::icon_set(system.file("icons", package = "ggicons")) ggplot(data.frame(x = 1:3, y = c(1, 3, 2)), aes(x, y)) + geom_point() + annotation_icon( icon = shapes$star, x = 2, y = 3, size = 12, colour = "steelblue" )library(ggplot2) # bundled placeholder shapes; a real pack (e.g. icons::fontawesome) works the same shapes <- icons::icon_set(system.file("icons", package = "ggicons")) ggplot(data.frame(x = 1:3, y = c(1, 3, 2)), aes(x, y)) + geom_point() + annotation_icon( icon = shapes$star, x = 2, y = 3, size = 12, colour = "steelblue" )
A ggplot2::draw_key() function that draws the icon itself as the
legend key glyph, instead of a generic point/rect. This is
geom_icon()'s default key_glyph; set key_glyph = draw_key_icon on
another geom to borrow it.
draw_key_icon(data, params, size)draw_key_icon(data, params, size)
data |
A single row data frame containing the scaled aesthetics to display in this key |
params |
A list of additional parameters supplied to the geom. |
size |
Width and height of key in mm. |
A grob.
library(ggplot2) # bundled placeholder shapes; a real pack (e.g. icons::fontawesome) works the same shapes <- icons::icon_set(system.file("icons", package = "ggicons")) # borrowed onto geom_point() so its legend key shows the mapped icon df <- data.frame(x = 1:3, y = c(1, 3, 2), cat = c("a", "b", "c")) ggplot(df, aes(x, y, colour = cat, icon = cat)) + geom_point(size = 10, key_glyph = draw_key_icon) + scale_icon_manual(values = c(shapes$square, shapes$circle, shapes$triangle))library(ggplot2) # bundled placeholder shapes; a real pack (e.g. icons::fontawesome) works the same shapes <- icons::icon_set(system.file("icons", package = "ggicons")) # borrowed onto geom_point() so its legend key shows the mapped icon df <- data.frame(x = 1:3, y = c(1, 3, 2), cat = c("a", "b", "c")) ggplot(df, aes(x, y, colour = cat, icon = cat)) + geom_point(size = 10, key_glyph = draw_key_icon) + scale_icon_manual(values = c(shapes$square, shapes$circle, shapes$triangle))
A theme element parallel to ggplot2::element_text(), for use in
axis.text, strip.text, legend.text, and similar theme settings.
Any label matching a name in icons is drawn as that icon; every other
label falls back to plain element_text() drawing.
element_icon( icons = NULL, ..., size = NULL, colour = NULL, inherit.blank = FALSE )element_icon( icons = NULL, ..., size = NULL, colour = NULL, inherit.blank = FALSE )
icons |
A named |
... |
Other arguments passed on to |
size |
Point size for text, and the point width/height for icons. |
colour |
Colour for text, and the fill colour for icons. |
inherit.blank |
icons is a named list() of individual, length-1 icons, one entry per
label to replace:
element_icon(icons = list( low = icons::fontawesome$solid$`battery-quarter`, high = icons::fontawesome$solid$`battery-full` ))
An element_icon object: a subclass of element_text (itself a
ggplot2 theme element), for use in ggplot2::theme().
library(ggplot2) # bundled placeholder shapes; a real pack (e.g. icons::fontawesome) works the same shapes <- icons::icon_set(system.file("icons", package = "ggicons")) cyl_icons <- list( `4` = shapes$circle, `6` = shapes$square, `8` = shapes$triangle ) ggplot(mtcars, aes(factor(cyl), mpg)) + geom_boxplot() + theme(axis.text.x = element_icon(icons = cyl_icons, size = 14)) # a real icon pack (here, Font Awesome) works the same way battery <- list( `4` = icons::fontawesome$solid$`battery-quarter`, `6` = icons::fontawesome$solid$`battery-half`, `8` = icons::fontawesome$solid$`battery-full` ) ggplot(mtcars, aes(factor(cyl), mpg)) + geom_boxplot() + theme(axis.text.x = element_icon(icons = battery, size = 14))library(ggplot2) # bundled placeholder shapes; a real pack (e.g. icons::fontawesome) works the same shapes <- icons::icon_set(system.file("icons", package = "ggicons")) cyl_icons <- list( `4` = shapes$circle, `6` = shapes$square, `8` = shapes$triangle ) ggplot(mtcars, aes(factor(cyl), mpg)) + geom_boxplot() + theme(axis.text.x = element_icon(icons = cyl_icons, size = 14)) # a real icon pack (here, Font Awesome) works the same way battery <- list( `4` = icons::fontawesome$solid$`battery-quarter`, `6` = icons::fontawesome$solid$`battery-half`, `8` = icons::fontawesome$solid$`battery-full` ) ggplot(mtcars, aes(factor(cyl), mpg)) + geom_boxplot() + theme(axis.text.x = element_icon(icons = battery, size = 14))
geom_icon() is a ggplot2::geom_point()-shaped geom that draws an
icon per row at (x, y), instead of a point. Icons come from the
icons package: single-fill
SVG vector shapes, parsed once per unique icon and cached, then
recoloured/rescaled/rotated per row at draw time.
geom_icon( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., size.unit = "mm", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )geom_icon( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., size.unit = "mm", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this layer.
When using a
|
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
... |
Other arguments passed on to
|
size.unit |
The unit in which the |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
A ggplot2 layer.
geom_icon() understands the following aesthetics (icon is required):
icon: the icon to draw, as an icon vector from the
icons package: an icon
object (e.g. from icons::read_icon() or
icons::fontawesome$solid$rocket) or an icons::icon_find() result.
Character ids are not resolved; map an actual icon vector.
x, y
colour/fill: both map to the icon's single fill colour (icons
don't have a separate border); fill wins when both are set.
alpha
size: the icon's width/height, in size.unit (default millimetres).
angle: rotation, in degrees.
stroke/linewidth don't apply: icons are filled shapes, not framed
ones.
geom_icon() understands the following aesthetics. Required aesthetics are displayed in bold and defaults are displayed for optional aesthetics:
| • | x |
|
| • | y |
|
| • | icon |
|
| • | alpha |
→ NA |
| • | angle |
→ 0 |
| • | colour |
→ "black" |
| • | fill |
→ NA |
| • | group |
→ inferred |
| • | size |
→ 6
|
Learn more about setting these aesthetics in vignette("ggplot2-specs").
draw_key_icon(), scale_icon_identity(), scale_icon_manual()
library(ggplot2) # bundled placeholder shapes; a real pack (e.g. icons::fontawesome) works the same shapes <- icons::icon_set(system.file("icons", package = "ggicons")) df <- data.frame( x = 1:3, y = c(1, 3, 2), icon = c(shapes$square, shapes$circle, shapes$triangle) ) ggplot(df, aes(x, y, icon = icon)) + geom_icon(size = 10, colour = "steelblue")library(ggplot2) # bundled placeholder shapes; a real pack (e.g. icons::fontawesome) works the same shapes <- icons::icon_set(system.file("icons", package = "ggicons")) df <- data.frame( x = 1:3, y = c(1, 3, 2), icon = c(shapes$square, shapes$circle, shapes$triangle) ) ggplot(df, aes(x, y, icon = icon)) + geom_icon(size = 10, colour = "steelblue")
geom_pictogram() draws a value as a grid of repeated icons, some
fraction of them filled in and the rest left faded. The same geom
produces a single-row rating widget, a waffle/percentage chart, or a
growing isotype-style unit chart, depending on the grid arguments
(n/nrow/ncol/symbol_value) passed to stat_pictogram().
geom_pictogram( mapping = NULL, data = NULL, stat = "pictogram", position = "identity", ..., n = NULL, nrow = NULL, ncol = NULL, symbol_value = NULL, n_target = 20, flow = "row", size.unit = "mm", spacing = 0.2, hjust = NULL, vjust = NULL, empty.colour = "grey85", empty.alpha = NULL, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )geom_pictogram( mapping = NULL, data = NULL, stat = "pictogram", position = "identity", ..., n = NULL, nrow = NULL, ncol = NULL, symbol_value = NULL, n_target = 20, flow = "row", size.unit = "mm", spacing = 0.2, hjust = NULL, vjust = NULL, empty.colour = "grey85", empty.alpha = NULL, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this layer.
When using a
|
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
... |
Other arguments passed on to
|
n |
Total slots in the grid (fixed-grid mode). |
nrow, ncol
|
Grid shape. Set at most one; the other is derived to
wrap the slots. Both |
symbol_value |
The data value one slot represents. |
n_target |
In growing mode, roughly how many icons deep the growing
dimension should get for the layer's largest value, when
|
flow |
Fill order: |
size.unit |
The unit |
spacing |
Gap between adjacent icons, as a fraction of |
hjust, vjust
|
Where the grid sits relative to |
empty.colour, empty.alpha
|
Colour and alpha for empty slots.
|
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
A ggplot2 layer.
geom_pictogram() understands the following aesthetics (value and
icon are required):
x, y: the grid's anchor position. Leaving one out draws a
bar/column chart instead of a fixed-position grid; see
stat_pictogram()'s Orientation section.
value: the magnitude a pictogram represents. stat_pictogram()
turns it into a filled slot count using symbol_value, the amount one
icon stands for. Also drives an automatic guide_pictogram() legend
spelling that ratio out; turn it off with guides(value = "none").
icon: the icon drawn in every slot, filled or empty (as in
geom_icon()).
colour/fill: the filled-slot colour; empty slots use
empty.colour instead.
alpha, angle, size: as in geom_icon().
geom_pictogram() understands the following aesthetics. Required aesthetics are displayed in bold and defaults are displayed for optional aesthetics:
| • | value |
|
| • | icon |
|
| • | alpha |
→ NA |
| • | angle |
→ 0 |
| • | colour |
→ "black" |
| • | fill |
→ NA |
| • | group |
→ inferred |
| • | size |
→ NA
|
Learn more about setting these aesthetics in vignette("ggplot2-specs").
stat_pictogram(), geom_icon(), guide_pictogram()
library(ggplot2) # bundled placeholder shapes; a real pack (e.g. icons::fontawesome) works the same shapes <- icons::icon_set(system.file("icons", package = "ggicons")) # 10x10 waffle: 37% ggplot(NULL, aes(x = "Proportion", value = 37)) + geom_pictogram(icon = shapes$square, n = 100, nrow = 10) # single-row rating: 5 slots, 3 filled, legend switched off ggplot(NULL, aes(y = "Rating", value = 3)) + geom_pictogram(icon = shapes$star, n = 5, colour = "goldenrod") + guides(value = "none") # growing isotype chart: two categories, each sized to its own value pets <- data.frame(animal = c("Cat", "Dog"), count = c(23, 15)) ggplot(pets, aes(animal, y = "Pet", value = count, icon = animal, colour = animal)) + geom_pictogram(nrow = 5) + scale_icon_manual(values = c(icons::fontawesome$solid$cat, icons::fontawesome$solid$dog)) # column chart: no y aesthetic, so icons fill like a column geometry commutes <- data.frame(mode = c("Bicycle", "Car"), count = c(890, 1230)) ggplot(commutes, aes(mode, value = count, icon = mode, colour = mode)) + geom_pictogram(ncol = 5) + scale_icon_manual(values = c(icons::fontawesome$solid$bicycle, icons::fontawesome$solid$car)) + labs(value = "commuters")library(ggplot2) # bundled placeholder shapes; a real pack (e.g. icons::fontawesome) works the same shapes <- icons::icon_set(system.file("icons", package = "ggicons")) # 10x10 waffle: 37% ggplot(NULL, aes(x = "Proportion", value = 37)) + geom_pictogram(icon = shapes$square, n = 100, nrow = 10) # single-row rating: 5 slots, 3 filled, legend switched off ggplot(NULL, aes(y = "Rating", value = 3)) + geom_pictogram(icon = shapes$star, n = 5, colour = "goldenrod") + guides(value = "none") # growing isotype chart: two categories, each sized to its own value pets <- data.frame(animal = c("Cat", "Dog"), count = c(23, 15)) ggplot(pets, aes(animal, y = "Pet", value = count, icon = animal, colour = animal)) + geom_pictogram(nrow = 5) + scale_icon_manual(values = c(icons::fontawesome$solid$cat, icons::fontawesome$solid$dog)) # column chart: no y aesthetic, so icons fill like a column geometry commutes <- data.frame(mode = c("Bicycle", "Car"), count = c(890, 1230)) ggplot(commutes, aes(mode, value = count, icon = mode, colour = mode)) + geom_pictogram(ncol = 5) + scale_icon_manual(values = c(icons::fontawesome$solid$bicycle, icons::fontawesome$solid$car)) + labs(value = "commuters")
guide_pictogram() is the default guide for scale_value_continuous()
(and so, automatically, for geom_pictogram()'s value aesthetic): a
one-entry legend spelling out the ratio every pictogram already encodes
but never states: one icon, labelled with the symbol_value it stands
for (e.g. an icon glyph next to "= 1000"), the way an infographic
isotype chart captions "each icon represents 1000 units" or a map's
scale bar does for distance.
guide_pictogram( title = ggplot2::waiver(), symbol_value = NULL, label = NULL, icon = NULL, theme = NULL, position = NULL, direction = NULL, override.aes = list(), order = 0, ... )guide_pictogram( title = ggplot2::waiver(), symbol_value = NULL, label = NULL, icon = NULL, theme = NULL, position = NULL, direction = NULL, override.aes = list(), order = 0, ... )
title |
The legend title. Defaults to the |
symbol_value |
Override the ratio shown, instead of reading it from the matched layer. Rarely needed. |
label |
Override the key's label text entirely, instead of the
default |
icon |
Which icon to draw in the key. Only needed when the matched
layer's |
theme |
A |
position |
A character string indicating where the legend should be placed relative to the plot panels. One of "top", "right", "bottom", "left", or "inside". |
direction |
A character string indicating the direction of the guide. One of "horizontal" or "vertical". |
override.aes |
A list specifying aesthetic parameters of legend key. See details and examples. |
order |
positive integer less than 99 that specifies the order of this guide among multiple guides. This controls the order in which multiple guides are displayed, not the contents of the guide itself. If 0 (default), the order is determined by a secret algorithm. |
... |
ignored. |
Unlike a standard legend, this never shows one key per break:
symbol_value is a single ratio, not something that varies over
value's range, so there is only ever one row to show, and it comes
from the matched geom_pictogram() layer's own symbol_value rather
than from the scale's trained breaks.
A ggplot2 guide.
scale_value_continuous(), geom_pictogram()
library(ggplot2) # bundled placeholder shapes; a real pack (e.g. icons::fontawesome) works the same shapes <- icons::icon_set(system.file("icons", package = "ggicons")) # legend reads "[square] = 1": each square is one percentage point ggplot(NULL, aes(x = "Proportion", value = 37)) + geom_pictogram(icon = shapes$square, n = 100, nrow = 10) + labs(value = "%") # a unit chart where each icon is worth 5: the legend spells that out pets <- data.frame(animal = c("Cat", "Dog"), count = c(23, 15)) ggplot(pets, aes(animal, value = count, icon = animal, colour = animal)) + geom_pictogram(symbol_value = 5) + scale_icon_manual(values = c(icons::fontawesome$solid$cat, icons::fontawesome$solid$dog)) + labs(value = "pets")library(ggplot2) # bundled placeholder shapes; a real pack (e.g. icons::fontawesome) works the same shapes <- icons::icon_set(system.file("icons", package = "ggicons")) # legend reads "[square] = 1": each square is one percentage point ggplot(NULL, aes(x = "Proportion", value = 37)) + geom_pictogram(icon = shapes$square, n = 100, nrow = 10) + labs(value = "%") # a unit chart where each icon is worth 5: the legend spells that out pets <- data.frame(animal = c("Cat", "Dog"), count = c(23, 15)) ggplot(pets, aes(animal, value = count, icon = animal, colour = animal)) + geom_pictogram(symbol_value = 5) + scale_icon_manual(values = c(icons::fontawesome$solid$cat, icons::fontawesome$solid$dog)) + labs(value = "pets")
scale_icon_identity() is for the common case where the icon
aesthetic is already mapped to icon values (an icon vector from the
icons package), so the data
is passed through unchanged rather than looked up in a palette. No legend
is drawn by default, as with ggplot2::scale_shape_identity().
scale_icon_identity( name = ggplot2::waiver(), ..., guide = "none", aesthetics = "icon" )scale_icon_identity( name = ggplot2::waiver(), ..., guide = "none", aesthetics = "icon" )
name |
The name of the scale. Used as the axis or legend title. If
|
... |
Other arguments passed on to |
guide |
Guide to use for this scale. Defaults to |
aesthetics |
Character string(s) naming the aesthetic(s) this scale
works with, defaulting to |
Requesting a legend (guide = "legend") isn't supported here: ggplot2's
discrete scale training only recognises character/factor data, not icon
vectors. Use scale_icon_manual() instead when a legend is needed.
A ggplot2 scale.
library(ggplot2) # bundled placeholder shapes; a real pack (e.g. icons::fontawesome) works the same shapes <- icons::icon_set(system.file("icons", package = "ggicons")) df <- data.frame( x = 1:3, y = c(1, 3, 2), icon = c(shapes$square, shapes$circle, shapes$triangle) ) # applied automatically for an icon-vector aesthetic; shown explicitly here ggplot(df, aes(x, y, icon = icon)) + geom_icon(size = 10) + scale_icon_identity()library(ggplot2) # bundled placeholder shapes; a real pack (e.g. icons::fontawesome) works the same shapes <- icons::icon_set(system.file("icons", package = "ggicons")) df <- data.frame( x = 1:3, y = c(1, 3, 2), icon = c(shapes$square, shapes$circle, shapes$triangle) ) # applied automatically for an icon-vector aesthetic; shown explicitly here ggplot(df, aes(x, y, icon = icon)) + geom_icon(size = 10) + scale_icon_identity()
scale_icon_manual() maps a discrete data value (e.g. a category
column) to an icon, using a manually-specified lookup, the icon
analogue of ggplot2::scale_shape_manual(). There's no automatic
discrete palette for icons, so values is required.
scale_icon_manual(..., values, breaks = ggplot2::waiver(), na.value = NA)scale_icon_manual(..., values, breaks = ggplot2::waiver(), na.value = NA)
... |
Arguments passed on to
|
values |
An icon vector from the
icons package, the same
length as the number of levels to map. Unlike most |
breaks |
One of:
|
na.value |
The aesthetic value to use for missing ( |
A ggplot2 scale.
library(ggplot2) # bundled placeholder shapes; a real pack (e.g. icons::fontawesome) works the same shapes <- icons::icon_set(system.file("icons", package = "ggicons")) df <- data.frame( x = 1:3, y = c(1, 3, 2), type = c("a", "b", "c") ) ggplot(df, aes(x, y, icon = type)) + geom_icon(size = 10) + scale_icon_manual(values = c(shapes$square, shapes$circle, shapes$triangle))library(ggplot2) # bundled placeholder shapes; a real pack (e.g. icons::fontawesome) works the same shapes <- icons::icon_set(system.file("icons", package = "ggicons")) df <- data.frame( x = 1:3, y = c(1, 3, 2), type = c("a", "b", "c") ) ggplot(df, aes(x, y, icon = type)) + geom_icon(size = 10) + scale_icon_manual(values = c(shapes$square, shapes$circle, shapes$triangle))
scale_value_continuous() registers value (as mapped in
geom_pictogram()) as a real trained aesthetic, purely so it can carry a
default guide (see guide_pictogram()). It never rescales value
itself: symbol_value slot counts need the real data value, so the
palette is the identity function.
scale_value_continuous( name = ggplot2::waiver(), breaks = ggplot2::waiver(), labels = ggplot2::waiver(), limits = NULL, guide = "pictogram", ... )scale_value_continuous( name = ggplot2::waiver(), breaks = ggplot2::waiver(), labels = ggplot2::waiver(), limits = NULL, guide = "pictogram", ... )
name |
The name of the scale. Used as the axis or legend title. If
|
breaks |
One of:
|
labels |
One of the options below. Please note that when
|
limits |
One of:
|
guide |
The value legend's guide; defaults to |
... |
Arguments passed on to
|
Picked up automatically for aes(value = ...), so most plots never need
to call it directly. Exported for overriding guide or setting explicit
breaks.
A ggplot2 scale.
guide_pictogram(), geom_pictogram()
library(ggplot2) # bundled placeholder shapes; a real pack (e.g. icons::fontawesome) works the same shapes <- icons::icon_set(system.file("icons", package = "ggicons")) # applied automatically; shown explicitly here just to relabel the legend ggplot(NULL, aes(x = "Proportion", value = 37)) + geom_pictogram(icon = shapes$square, n = 100, nrow = 10) + scale_value_continuous(name = "%")library(ggplot2) # bundled placeholder shapes; a real pack (e.g. icons::fontawesome) works the same shapes <- icons::icon_set(system.file("icons", package = "ggicons")) # applied automatically; shown explicitly here just to relabel the legend ggplot(NULL, aes(x = "Proportion", value = 37)) + geom_pictogram(icon = shapes$square, n = 100, nrow = 10) + scale_value_continuous(name = "%")
stat_pictogram() turns one row of data (an anchor position and a
value) into one row per icon slot in a grid, ready for
geom_pictogram() to draw. It's the counting/layout half of a pictogram.
stat_pictogram( mapping = NULL, data = NULL, geom = "pictogram", position = "identity", ..., n = NULL, nrow = NULL, ncol = NULL, symbol_value = NULL, n_target = 20, flow = "row", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )stat_pictogram( mapping = NULL, data = NULL, geom = "pictogram", position = "identity", ..., n = NULL, nrow = NULL, ncol = NULL, symbol_value = NULL, n_target = 20, flow = "row", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
geom |
Override the default connection between |
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
... |
Other arguments passed on to
|
n |
Total slots in the grid (fixed-grid mode). |
nrow, ncol
|
Grid shape. Set at most one; the other is derived to
wrap the slots. Both |
symbol_value |
The data value one slot represents. |
n_target |
In growing mode, roughly how many icons deep the growing
dimension should get for the layer's largest value, when
|
flow |
Fill order: |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
A ggplot2 layer.
Two modes, chosen by whether n (or both nrow and ncol) is set:
Fixed grid (n, or both nrow/ncol, given): the grid always has
n slots; round(value / symbol_value) of them are filled (capped at
n), the rest empty. This is the waffle-chart/rating-widget shape:
proportions vary, the grid footprint doesn't.
Growing grid (n, nrow and ncol all left NULL, or only one of
nrow/ncol given): the grid has exactly round(value / symbol_value)
slots, all filled. An isotype/unit-chart shape where more icons is
the value, so the footprint grows with it.
At most one of nrow/ncol needs setting; the other wraps to fit. With
neither set, the grid defaults to a single row, unless x/y asks for a
bar/column shape instead; see Orientation below.
x and y are the grid's anchor, but only value is actually required.
Map both and you get a fixed-position grid, centred on (x, y): a
waffle chart or rating widget. Leave one unmapped and that becomes the
growth axis of a bar-style stack instead, anchored to that edge of the
plot panel. aes(x = category, value = count) draws a column chart,
one growing column per category, up from the bottom of the panel;
aes(y = category, value = count) draws a horizontal bar, growing
right from the left of the panel.
library(ggplot2) # bundled placeholder shapes; a real pack (e.g. icons::fontawesome) works the same shapes <- icons::icon_set(system.file("icons", package = "ggicons")) # only needed directly when pairing with a different geom ggplot(NULL, aes(x = "Proportion", value = 37)) + stat_pictogram(geom = "pictogram", icon = shapes$square, n = 100, nrow = 10)library(ggplot2) # bundled placeholder shapes; a real pack (e.g. icons::fontawesome) works the same shapes <- icons::icon_set(system.file("icons", package = "ggicons")) # only needed directly when pairing with a different geom ggplot(NULL, aes(x = "Proportion", value = 37)) + stat_pictogram(geom = "pictogram", icon = shapes$square, n = 100, nrow = 10)