| Title: | Icon Geometries for 'ggplot2' |
| Version: | 0.1.0 |
| 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. |
| License: | MIT + file LICENSE |
| URL: | https://pkg.mitchelloharawild.com/ggicons/, https://github.com/mitchelloharawild/ggicons |
| BugReports: | https://github.com/mitchelloharawild/ggicons/issues |
| Imports: | cli, ggplot2 (≥ 4.0.0), grid, grImport2, icons (≥ 1.0.0), rlang (≥ 1.1.0), rsvg, scales, vctrs |
| Suggests: | spelling, testthat (≥ 3.0.0) |
| Config/roxygen2/version: | 8.0.0 |
| Config/testthat/edition: | 3 |
| Encoding: | UTF-8 |
| RoxygenNote: | 8.0.0 |
| Language: | en-GB |
| NeedsCompilation: | no |
| Packaged: | 2026-09-08 00:13:07 UTC; mitchell |
| Author: | Mitchell O'Hara-Wild
|
| Maintainer: | Mitchell O'Hara-Wild <mail@mitchelloharawild.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-09-15 13:10:02 UTC |
ggicons: Icon Geometries for 'ggplot2'
Description
Provides icon geometries for 'ggplot2', using vector icon sets from the 'icons' package. geom_icon() draws an icon per row in place of a point, styled with the usual colour, size, alpha and angle aesthetics. Icon data is passed straight through with scale_icon_identity(), or mapped from discrete values with scale_icon_manual(). Icons also appear in legend keys, as fixed-position markers with annotation_icon(), and as axis, strip and legend labels via the element_icon() theme element. geom_pictogram() draws isotype-style unit charts, waffle/percentage charts and rating widgets, encoding a value as a grid of repeated icons.
Author(s)
Maintainer: Mitchell O'Hara-Wild mail@mitchelloharawild.com (ORCID)
Authors:
Mitchell O'Hara-Wild mail@mitchelloharawild.com (ORCID)
See Also
Useful links:
Report bugs at https://github.com/mitchelloharawild/ggicons/issues
Annotate a plot with icons at fixed positions
Description
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.
Usage
annotation_icon(
icon,
x,
y,
colour = "black",
fill = NA,
size = 6,
alpha = NA,
angle = 0,
size.unit = "mm"
)
Arguments
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 |
Details
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))).
Value
A ggplot2 layer.
Aesthetics
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. fromicons::read_icon()oricons::fontawesome$solid$rocket) or anicons::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);fillwins when both are set. -
alpha -
size: the icon's width/height, insize.unit(default millimetres). -
angle: rotation, in degrees.
stroke/linewidth don't apply, since icons are filled shapes, not
framed ones.
See Also
Examples
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"
)
Legend key glyph: an icon
Description
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.
Usage
draw_key_icon(data, params, size)
Arguments
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. |
Value
A grob.
Examples
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))
Theme element: draw labels as icons
Description
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.
Usage
element_icon(
icons = NULL,
...,
size = NULL,
colour = NULL,
inherit.blank = FALSE
)
Arguments
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 |
Details
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` ))
Value
An element_icon object: a subclass of element_text (itself a
ggplot2 theme element), for use in ggplot2::theme().
See Also
Examples
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))
Icons
Description
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.
Usage
geom_icon(
mapping = NULL,
data = NULL,
stat = "identity",
position = "identity",
...,
size.unit = "mm",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE
)
Arguments
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 |
Value
A ggplot2 layer.
Aesthetics
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. fromicons::read_icon()oricons::fontawesome$solid$rocket) or anicons::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);fillwins when both are set. -
alpha -
size: the icon's width/height, insize.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").
See Also
draw_key_icon(), scale_icon_identity(), scale_icon_manual()
Examples
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")
Pictograms
Description
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().
Usage
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
)
Arguments
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 |
Value
A ggplot2 layer.
Aesthetics
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; seestat_pictogram()'s Orientation section. -
value: the magnitude a pictogram represents.stat_pictogram()turns it into a filled slot count usingsymbol_value, the amount one icon stands for. Also drives an automaticguide_pictogram()legend spelling that ratio out; turn it off withguides(value = "none"). -
icon: the icon drawn in every slot, filled or empty (as ingeom_icon()). -
colour/fill: the filled-slot colour; empty slots useempty.colourinstead. -
alpha,angle,size: as ingeom_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").
See Also
stat_pictogram(), geom_icon(), guide_pictogram()
Examples
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")
Pictogram value guide
Description
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.
Usage
guide_pictogram(
title = ggplot2::waiver(),
symbol_value = NULL,
label = NULL,
icon = NULL,
theme = NULL,
position = NULL,
direction = NULL,
override.aes = list(),
order = 0,
...
)
Arguments
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. |
Details
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.
Value
A ggplot2 guide.
See Also
scale_value_continuous(), geom_pictogram()
Examples
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")
Use icon values as-is
Description
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().
Usage
scale_icon_identity(
name = ggplot2::waiver(),
...,
guide = "none",
aesthetics = "icon"
)
Arguments
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 |
Details
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.
Value
A ggplot2 scale.
See Also
Examples
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()
Map discrete values to icons manually
Description
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.
Usage
scale_icon_manual(..., values, breaks = ggplot2::waiver(), na.value = NA)
Arguments
... |
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 ( |
Value
A ggplot2 scale.
See Also
Examples
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))
Discrete scale for the icon aesthetic
Description
Tells ggplot2's scale machinery that an icon vector from the
icons package is discrete,
the same way a bare factor/character column already is. Without this,
scale_type.default() warns and defaults to continuous, which is wrong
for icons.
Usage
## S3 method for class 'icons'
scale_type(x)
Arguments
x |
A vector mapped to an aesthetic. |
Details
This purely silences that warning: icon has no automatic discrete
palette (see scale_icon_manual()).
Value
"discrete".
Continuous scale for the pictogram value aesthetic
Description
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.
Usage
scale_value_continuous(
name = ggplot2::waiver(),
breaks = ggplot2::waiver(),
labels = ggplot2::waiver(),
limits = NULL,
guide = "pictogram",
...
)
Arguments
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
|
Details
Picked up automatically for aes(value = ...), so most plots never need
to call it directly. Exported for overriding guide or setting explicit
breaks.
Value
A ggplot2 scale.
See Also
guide_pictogram(), geom_pictogram()
Examples
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 = "%")
Pictogram grid layout
Description
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.
Usage
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
)
Arguments
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 |
Value
A ggplot2 layer.
Grid sizing
Two modes, chosen by whether n (or both nrow and ncol) is set:
-
Fixed grid (
n, or bothnrow/ncol, given): the grid always hasnslots;round(value / symbol_value)of them are filled (capped atn), the rest empty. This is the waffle-chart/rating-widget shape: proportions vary, the grid footprint doesn't. -
Growing grid (
n,nrowandncolall leftNULL, or only one ofnrow/ncolgiven): the grid has exactlyround(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.
Orientation
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.
See Also
Examples
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)