Skip to contents

geom_area_watercolor() draws areas filled as if with a brush, as the watercolor counterpart of ggplot2::geom_area(). geom_density_watercolor() does the same for kernel density estimates, as the counterpart of ggplot2::geom_density().

Usage

geom_area_watercolor(
  mapping = NULL,
  data = NULL,
  stat = "align",
  position = "stack",
  ...,
  by = c("feature", "fill"),
  blend = c("over", "multiply"),
  monochrome = FALSE,
  pooling = 0.25,
  pooling_size = 12,
  rim = 0.25,
  rim_width = 0.5,
  wobble = 0.4,
  wobble_size = 2.5,
  granulation = 0.35,
  grain_size = 0.25,
  dpi = 300,
  seed = NULL,
  orientation = NA,
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = TRUE
)

geom_density_watercolor(
  mapping = NULL,
  data = NULL,
  stat = "density",
  position = "identity",
  ...,
  by = c("feature", "fill"),
  blend = c("over", "multiply"),
  monochrome = FALSE,
  pooling = 0.25,
  pooling_size = 12,
  rim = 0.25,
  rim_width = 0.5,
  wobble = 0.4,
  wobble_size = 2.5,
  granulation = 0.35,
  grain_size = 0.25,
  dpi = 300,
  seed = NULL,
  orientation = NA,
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = TRUE
)

Arguments

mapping

Set of aesthetic mappings created by aes(). If specified and inherit.aes = TRUE (the default), it is combined with the default mapping at the top level of the plot. You must supply mapping if there is no plot mapping.

data

The data to be displayed in this layer. There are three options:

If NULL, the default, the data is inherited from the plot data as specified in the call to ggplot().

A data.frame, or other object, will override the plot data. All objects will be fortified to produce a data frame. See fortify() for which variables will be created.

A function will be called with a single argument, the plot data. The return value must be a data.frame, and will be used as the layer data. A function can be created from a formula (e.g. ~ head(.x, 10)).

stat

The statistical transformation to use on the data for this layer. When using a geom_*() function to construct a layer, the stat argument can be used to override the default coupling between geoms and stats. The stat argument accepts the following:

  • A Stat ggproto subclass, for example StatCount.

  • A string naming the stat. To give the stat as a string, strip the function name of the stat_ prefix. For example, to use stat_count(), give the stat as "count".

  • For more information and other ways to specify the stat, see the layer stat documentation.

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 position argument accepts the following:

  • The result of calling a position function, such as position_jitter(). This method allows for passing extra arguments to the position.

  • A string naming the position adjustment. To give the position as a string, strip the function name of the position_ prefix. For example, to use position_jitter(), give the position as "jitter".

  • For more information and other ways to specify the position, see the layer position documentation.

...

Other arguments passed on to ggplot2::layer()'s params argument. For geom_density_watercolor() these include the arguments of ggplot2::stat_density(), such as bw and adjust.

by

What to paint in one go: "feature" for each area on its own, or "fill" for areas that share a fill and alpha together.

blend

How to combine paint where painted areas in the layer overlap: "over" lets later paint cover earlier paint, and "multiply" darkens the overlap as layered pigment would. See the section on blending.

monochrome

If TRUE, paint in greys instead of colours. Each colour becomes the grey of the same lightness, so mapped fills keep their order from light to dark.

pooling

Variation in the opacity of the paint across a shape, where 0 is a flat fill.

pooling_size

Approximate size of the variations in opacity, in millimetres.

rim

Extra opacity where pigment collects at the edge of the paint, where 0 is none.

rim_width

Distance over which the rim fades into the fill, in millimetres.

wobble

How far the edge of the paint strays from the edge of the shape, in millimetres. Use 0 to follow the shape exactly.

wobble_size

Approximate size of the strays in the edge, in millimetres.

granulation

Strength of the pigment grain, where 0 is none.

grain_size

Approximate size of the grain, in millimetres.

dpi

Resolution of the paint, in cells per inch.

seed

A single integer that fixes the noise in the paint. If NULL, the layer chooses a seed at random when you create the layer.

orientation

The orientation of the layer. The default (NA) automatically determines the orientation from the aesthetic mapping. In the rare event that this fails it can be given explicitly by setting orientation to either "x" or "y". See the Orientation section for more detail.

na.rm

If FALSE, the default, missing values are removed with a warning. If TRUE, missing values are silently removed.

show.legend

logical. Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped. FALSE never includes, and TRUE always includes. It can also be a named logical vector to finely select the aesthetics to display. To include legend keys for all levels, even when no data exists, use TRUE. If NA, all levels are shown in legend, but unobserved levels are omitted.

inherit.aes

If FALSE, overrides the default aesthetics, rather than combining with them. This is most useful for helper functions that define both data and aesthetics and shouldn't inherit behaviour from the default plot specification, e.g. annotation_borders().

Value

A ggplot2 layer.

Details

Overlapping densities are a good use of blend = "multiply", which darkens the paint where areas overlap instead of covering one with another. A lower alpha keeps the overlaps legible.

Aesthetics

Both geoms understand the following aesthetics:

  • x and y. geom_area_watercolor() requires both. geom_density_watercolor() requires one, and computes the other.

  • group, which separates the areas.

  • fill, the colour of the paint.

  • alpha, the typical opacity of the paint.

Examples

library(ggplot2)

ggplot(economics, aes(date, unemploy)) +
  geom_area_watercolor(seed = 1) +
  theme_paper()


ggplot(mpg, aes(hwy, fill = drv)) +
  geom_density_watercolor(blend = "multiply", alpha = 0.35, seed = 1) +
  theme_paper()