ggwatercolor draws ordinary ggplot2 charts in the style of watercolor
paint. This article shows the chart geoms in the package and the
settings that change how the paint looks. For maps, see
vignette("maps").
Columns, areas, and densities
Four geoms fill shapes with uneven paint.
| Watercolor geom | ggplot2 geom |
|---|---|
geom_col_watercolor() |
geom_col() |
geom_area_watercolor() |
geom_area() |
geom_density_watercolor() |
geom_density() |
geom_polygon_watercolor() |
geom_polygon() |
These geoms take the place of the ggplot2 geoms and accept the same aesthetics.
ggplot(economics, aes(date, unemploy / 1000)) +
geom_area_watercolor(seed = 1) +
labs(x = NULL, y = "Unemployed (millions)") +
theme_paper()
geom_col_watercolor() uses the values in the data as the
heights of the columns. Use stat = "count" to count the
rows in each group.
Paint settings
Four settings control the look of a fill.
-
poolingsets how much the opacity changes across the fill. -
rimsets how much extra pigment collects at the edge. -
wobblesets how far the edge of the paint moves from the edge of the shape. -
granulationsets the strength of the pigment grain.
library(patchwork)
column_chart <- function(title, ...) {
ggplot(mpg, aes(drv)) +
geom_col_watercolor(stat = "count", seed = 1, ...) +
labs(title = title, x = "Drive", y = "Cars") +
theme_paper(base_size = 9)
}
column_chart("Flat", pooling = 0, rim = 0, wobble = 0, granulation = 0) +
column_chart("Default") +
column_chart("Strong", pooling = 0.6, rim = 0.5, wobble = 0.8) +
plot_annotation(theme = theme_paper())
By default, the layer paints each shape separately. Use
by = "fill" to paint all shapes of one colour as a single
area.
Points and smooths
geom_point_watercolor() draws each point as a small disc
of paint. geom_smooth_watercolor() paints the confidence
band of a smooth as a pale wash, and the fitted line as a brush stroke.
These two geoms use the colour aesthetic for the colour of
the paint, as geom_point() and geom_smooth()
do.
ggplot(mpg, aes(displ, hwy, colour = drv)) +
geom_point_watercolor(alpha = 0.3, size = 2.5, seed = 1) +
geom_smooth_watercolor(method = "lm", formula = y ~ x, seed = 2) +
scale_colour_manual(values = c("#B9794F", "#4E9DB5", "#D9B25A")) +
labs(x = "Displacement (litres)", y = "Highway miles per gallon", colour = "Drive") +
theme_paper()
The layer paints each point separately, which takes about a hundredth
of a second for each point. For thousands of points, use
by = "fill" to paint all points of one colour together.
Lines
geom_line_watercolor() and
geom_path_watercolor() paint each line as one stroke of a
brush. The stroke gets wider and narrower along the line, and narrows at
each end. linewidth sets the typical width in
millimetres.
ggplot(economics, aes(date, unemploy / 1000)) +
geom_line_watercolor(linewidth = 1.6, seed = 1) +
labs(x = NULL, y = "Unemployed (millions)") +
theme_paper()
Two more settings change the paint along the line.
pigment_variation makes the paint thicker and thinner, as
when a brush runs low on paint. dry_brush breaks the thin
passages into fine streaks. Both settings are 0 by default. Use them
with care on a chart. The changes are random, so a pale passage does not
reflect the data.
Blending
When painted areas in one layer overlap, later paint covers earlier
paint. Set blend = "multiply" to darken the overlap
instead, in the way that layers of pigment do. A lower
alpha keeps the overlaps easy to read.
ggplot(mpg, aes(hwy, fill = drv)) +
geom_density_watercolor(blend = "multiply", alpha = 0.35, seed = 2) +
scale_fill_manual(values = c("#B9794F", "#4E9DB5", "#D9B25A")) +
labs(x = "Highway miles per gallon", y = "Density", fill = "Drive") +
theme_paper()
blend applies inside one layer. To blend a layer with
the layers below it, use the ggblend package.
Monochrome
Set monochrome = TRUE to paint in greys. Each colour
becomes the grey of the same lightness. All the chart geoms accept this
argument. Give the argument to each layer that you want in grey.
Greys have an order from light to dark, and a reader sees that order
in the data. For this reason, do not use monochrome with a
colour scale for categories that have no order. Two categories can also
get greys that are too close to tell apart. Use it for one colour, or
for a scale that goes from light to dark, as in this example.
ggplot(mpg[mpg$cyl != 5, ], aes(hwy, fill = factor(cyl))) +
geom_density_watercolor(monochrome = TRUE, seed = 2) +
scale_fill_manual(values = c("#D9C3A5", "#B9794F", "#5E3A22")) +
labs(x = "Highway miles per gallon", y = "Density", fill = "Cylinders") +
theme_paper()
Seeds
The paint uses random noise. If you do not set seed,
each layer picks a seed when you create the layer. The plot then looks
the same each time you draw it, but a new call gives a different
picture. Set seed to get the same picture from the same
code.
Sizes are lengths on the page
ggwatercolor computes the paint when the device draws the plot. The
settings that control size are in millimetres on the page, not in the
units of the data. A fill with rim_width = 0.5 has a rim
about 0.5 mm wide in a panel of any size.
Paper
theme_paper() puts the plot on paper and keeps the axes
and a light grid. theme_paper_void() removes all parts of
the plot except the paper.
The paper argument sets the colour of the paper.
"neutral" is the default. "warm" is more
yellow. You can also give any colour.
The paper is flat by default. Set texture to give the
paper a fine tooth.
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
labs(x = "Displacement (litres)", y = "Highway miles per gallon") +
theme_paper(paper = "warm", texture = 0.05)
If you combine plots with patchwork, also give the theme to
plot_annotation(theme = ). Otherwise the space between the
plots stays white.
Resolution and speed
Each paint layer is a raster image. The dpi argument
sets the resolution of the image. The default is 300. Use a lower value
to draw faster, or a higher value for print.
For a very large panel, ggwatercolor lowers the resolution and gives
a warning. To change the limit, set the
ggwatercolor.max_cells option.