Learn R Programming

ggsketch (version 2.0.0)

scale_pressure_continuous: Continuous scale for the sketch pressure aesthetic

Description

geom_sketch_line() and geom_sketch_path() let you map a variable to pressure (aes(pressure = z)) so the stroke swells and thins along the line, like a real pen pressed harder in places. This scale rescales that variable's observed range to a band of width multipliers, just as scale_size() rescales to a size range. It is applied automatically whenever pressure is mapped to a continuous variable, so you only call it directly to change range. To use values as raw width multipliers with no rescaling, wrap them in base::I() (aes(pressure = I(z))).

Usage

scale_pressure_continuous(..., range = c(0.2, 1.6), guide = "none")

scale_pressure(..., range = c(0.2, 1.6), guide = "none")

Value

A ggplot2 scale object.

Arguments

...

Other arguments passed to ggplot2::continuous_scale().

range

Output width-multiplier range. Default c(0.2, 1.6): the lightest pressure draws the stroke at 0.2x its base width, the heaviest at 1.6x.

guide

Legend guide. Defaults to "none" because the legend keys do not reflect pressure; set to "legend" to show one anyway.

Details

Mapping pressure renders the line through the variable-width stroke_ribbon() engine even under the default medium = "pen", and combines with a non-pen medium (the medium's own width profile is multiplied by the mapped pressure).

See Also

Other sketch-theme: CoordSketch, CoordSketchPolar, element_sketch_line(), ggsketch_check_fonts(), ggsketch_save(), register_sketch_font(), scale_roughness_continuous(), scale_sketch, scale_tone_continuous(), sketch_palette(), theme_sketch()

Examples

Run this code
library(ggplot2)

# A line whose width tracks a variable, rescaled to c(0.2, 1.6) automatically.
ggplot(economics[1:120, ], aes(date, unemploy, pressure = unemploy)) +
  geom_sketch_line(linewidth = 1, seed = 1L)

# Widen the band for a more dramatic swell.
ggplot(economics[1:120, ], aes(date, unemploy, pressure = unemploy)) +
  geom_sketch_line(linewidth = 1, seed = 1L) +
  scale_pressure_continuous(range = c(0.05, 2.5))

Run the code above in your browser using DataLab