| Title: | Plotting 'ggplot2' Graphics in an 'XKCD' Style |
|---|---|
| Description: | Provides custom geoms and themes to create charts and graphics in the distinctive, hand-drawn 'XKCD' webcomic style using the 'ggplot2' framework. The package utilizes custom layers for jittered lines, segments, circles, and figures, and includes a theme that supports the necessary 'XKCD' font. |
| Authors: | Emilio Torres-Manzanera [aut], Enrique Toledo [ctb, cre] |
| Maintainer: | Enrique Toledo <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.1 |
| Built: | 2026-09-18 08:56:13 UTC |
| Source: | https://github.com/toledoem/xkcd |
Provides custom geoms and themes to create charts and graphics in the distinctive, hand-drawn 'XKCD' webcomic style using the 'ggplot2' framework. The package utilizes custom layers for jittered lines, segments, circles, and figures, and includes a theme that supports the necessary 'XKCD' font.
The DESCRIPTION file:
| Package: | xkcd |
| Type: | Package |
| Title: | Plotting 'ggplot2' Graphics in an 'XKCD' Style |
| Version: | 0.1.1 |
| Date: | 2026-08-19 |
| Authors@R: | c( person(given = "Emilio", family = "Torres-Manzanera", role = "aut", email= "[email protected]"), person(given = "Enrique", family = "Toledo", role = c("ctb", "cre"), email = "[email protected]")) |
| VignetteBuilder: | knitr |
| Description: | Provides custom geoms and themes to create charts and graphics in the distinctive, hand-drawn 'XKCD' webcomic style using the 'ggplot2' framework. The package utilizes custom layers for jittered lines, segments, circles, and figures, and includes a theme that supports the necessary 'XKCD' font. |
| License: | MIT + file LICENSE |
| URL: | https://github.com/ToledoEM/xkcd, https://toledoem.github.io/xkcd/ |
| BugReports: | https://github.com/ToledoEM/xkcd/issues |
| Depends: | R (>= 4.0), ggplot2 (>= 3.4.0) |
| Imports: | Hmisc, stats, grid, extrafont |
| Suggests: | knitr, rmarkdown, zoo, reshape, splancs, pkgdown, palmerpenguins, dplyr, ggrepel, systemfonts, covr, testthat (>= 3.0.0) |
| Encoding: | UTF-8 |
| Config/testthat/edition: | 3 |
| Config/roxygen2/version: | 8.1.0 |
| Config/pak/sysreqs: | cmake make libicu-dev libuv1-dev |
| Repository: | https://toledoem.r-universe.dev |
| Date/Publication: | 2026-08-19 18:43:08 UTC |
| RemoteUrl: | https://github.com/toledoem/xkcd |
| RemoteRef: | HEAD |
| RemoteSha: | b9d5ebad85d5c91e32e815bdd59bb9332ad412f0 |
| Author: | Emilio Torres-Manzanera [aut], Enrique Toledo [ctb, cre] |
| Maintainer: | Enrique Toledo <[email protected]> |
Index of help topics:
geom_xkcdpath GeomXkcdPath: fuzzy path/circle geom (XKCD
style)
GeomXkcdRect GeomXkcdRect: fuzzy rectangle geom (XKCD style)
theme_xkcd Creates an XKCD theme
xkcd-package Plotting 'ggplot2' Graphics in an 'XKCD' Style
xkcdaxis Plot the axis
xkcdman Draw a stick figure
xkcdrect Draw fuzzy rectangles
Emilio Torres-Manzanera [aut], Enrique Toledo [ctb, cre]
Maintainer: Enrique Toledo <[email protected]>
## Not run: vignette("xkcd-intro")## Not run: vignette("xkcd-intro")
A ggplot2 geom that draws jittered, smoothed paths or fuzzy circles. It expects aesthetics like 'x', 'y', and either 'xend'/'yend' (for segments) or 'diameter' (for circles). Additional aesthetics (colour, alpha, linewidth, linetype) are respected.
geom_xkcdpath( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., xjitteramount = 0.01, yjitteramount = 0.01, wobble = 1, seed = NULL, mask = TRUE, show.legend = NA, inherit.aes = TRUE )geom_xkcdpath( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., xjitteramount = 0.01, yjitteramount = 0.01, wobble = 1, seed = NULL, mask = TRUE, show.legend = NA, inherit.aes = TRUE )
mapping |
Aesthetic mapping. |
data |
Data frame. |
stat |
The statistical transformation to use on the data for this layer. |
position |
Position adjustment. |
... |
Other arguments passed on to layer(). |
xjitteramount |
Horizontal jitter amount for segments, in data units. |
yjitteramount |
Vertical jitter amount for segments, in data units. |
wobble |
Scalar multiplier applied to both jitter amounts. '1' leaves the jitter amounts unchanged; '0' draws straight lines. |
seed |
Optional integer. When supplied the wobble is reproducible: the same 'seed' always yields the same path. Each row of 'data' is offset from 'seed' so rows still differ from one another. The global RNG state is left untouched. |
mask |
Logical; if TRUE draws a thicker white mask path under the main path. |
show.legend |
Show legend. |
inherit.aes |
Whether to inherit aesthetics from the plot. |
Draws each rectangle as a standard filled rect with four jittered, Bezier-smoothed border segments on top.
This function creates an XKCD theme, applying the 'xkcd' font if available.
theme_xkcd()theme_xkcd()
A theme object.
The "xkcd" font must be installed on your system for the full effect. Modern
graphics devices pick it up directly; registering it with extrafont is
only needed for pdf/postscript output. See the vignette
vignette("xkcd-intro") for installation instructions.
## Not run: # Assuming 'xkcd' font is installed and registered: p <- ggplot(mtcars, aes(mpg, wt)) + geom_point() + theme_xkcd() p ## End(Not run)## Not run: # Assuming 'xkcd' font is installed and registered: p <- ggplot(mtcars, aes(mpg, wt)) + geom_point() + theme_xkcd() p ## End(Not run)
This function plots the axis in an XKCD style.
xkcdaxis(xrange, yrange, ...)xkcdaxis(xrange, yrange, ...)
xrange |
The range of the X axe. |
yrange |
The range of the Y axe. |
... |
Other arguments passed to geom_xkcdpath. |
A list of layers containing the axes, coordinate system, and theme.
## Not run: xrange <- range(mtcars$mpg) yrange <- range(mtcars$wt) p <- ggplot() + geom_point(aes(mpg, wt), data=mtcars) + xkcdaxis(xrange,yrange) p ## End(Not run)## Not run: xrange <- range(mtcars$mpg) yrange <- range(mtcars$wt) p <- ggplot() + geom_point(aes(mpg, wt), data=mtcars) + xkcdaxis(xrange,yrange) p ## End(Not run)
Draws one stick figure per row of 'data'. The figure is built from eight fuzzy elements – a circular head plus seven bones (spine, two humeri, two radii and two legs) – which are emitted as just two [geom_xkcdpath()] layers.
xkcdman(mapping, data, seed = NULL, ...)xkcdman(mapping, data, seed = NULL, ...)
mapping |
Aesthetic mapping |
data |
Dataset |
seed |
Optional integer for a reproducible figure. See [geom_xkcdpath()]. |
... |
Optional arguments passed on to [geom_xkcdpath()]. |
The following aesthetics are required, supplied through 'mapping' or as columns of 'data': 'x' and 'y' (centre of the head), 'scale' (overall size), 'ratioxy' (the x/y scale ratio, which keeps the figure from being distorted when the axes have different units), and the angles 'angleofspine', 'anglerighthumerus', 'anglelefthumerus', 'anglerightradius', 'angleleftradius', 'anglerightleg', 'angleleftleg' and 'angleofneck'.
[geom_xkcdpath()]
It draws fuzzy rectangles.
xkcdrect( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., borderxjitteramount = 0.005, borderyjitteramount = 0.005, wobble = 1, seed = NULL, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, fillcolour, bordercolour, borderlinewidth )xkcdrect( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., borderxjitteramount = 0.005, borderyjitteramount = 0.005, wobble = 1, seed = NULL, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, fillcolour, bordercolour, borderlinewidth )
mapping |
Mapping between variables and aesthetics generated by |
data |
Dataset used in this layer. |
stat |
The statistical transformation to use on the data for this layer. |
position |
Position adjustment. |
... |
Other arguments passed on to |
borderxjitteramount |
Horizontal jitter amount for the border. |
borderyjitteramount |
Vertical jitter amount for the border. |
wobble |
Scalar multiplier applied to both jitter amounts. |
seed |
Optional integer for a reproducible border. See |
na.rm |
If |
show.legend |
Show legend. |
inherit.aes |
Whether to inherit aesthetics from the plot. |
fillcolour |
Deprecated. Use the |
bordercolour |
Deprecated. Use the |
borderlinewidth |
Deprecated. Use the |
This function draws rectangles with hand-drawn, wobbly borders.
The following aesthetics are required:
xmin
ymin
xmax
ymax
The fill and border are controlled with the standard fill,
colour and linewidth aesthetics, so they may be mapped to
variables in the usual way.
A layer.
## Not run: volunteers <- data.frame(year = c(2007:2011), number = c(56470, 56998, 59686, 61783, 64251)) xrange <- range(volunteers$year) yrange <- range(volunteers$number) p <- ggplot() + xkcdrect(aes(xmin = year - 0.2, xmax = year + 0.2, ymin = number - 500, ymax = number + 500), data = volunteers, fill = "pink", linewidth = 1.2) + geom_point(aes(x = year, y = number), data = volunteers) + xkcdaxis(xrange, yrange) + theme_xkcd() p ## End(Not run)## Not run: volunteers <- data.frame(year = c(2007:2011), number = c(56470, 56998, 59686, 61783, 64251)) xrange <- range(volunteers$year) yrange <- range(volunteers$number) p <- ggplot() + xkcdrect(aes(xmin = year - 0.2, xmax = year + 0.2, ymin = number - 500, ymax = number + 500), data = volunteers, fill = "pink", linewidth = 1.2) + geom_point(aes(x = year, y = number), data = volunteers) + xkcdaxis(xrange, yrange) + theme_xkcd() p ## End(Not run)