Learn R Programming

ggsketch (version 2.0.0)

CoordSketch: A hand-drawn coordinate system

Description

A drop-in replacement for ggplot2::coord_cartesian() that draws the frame hand-drawn: the panel gridlines and axis ticks are rendered as roughened sketch grobs, so the frame matches the marks -- under any theme, not only theme_sketch(). It reuses ggplot2's own gridline and axis layout and only swaps how those elements are drawn, so limits, expansion, and clipping behave exactly like coord_cartesian().

Usage

coord_sketch(
  xlim = NULL,
  ylim = NULL,
  expand = TRUE,
  default = FALSE,
  clip = "on",
  roughness = 0.5,
  bowing = 0.5,
  n_passes = 2L,
  seed = NULL,
  rough_grid = TRUE,
  rough_ticks = TRUE
)

Value

A ggproto Coord object to add to a plot.

Arguments

xlim, ylim

Limits for the x and y axes (as in ggplot2::coord_cartesian()).

expand

If TRUE (default), add the standard expansion around the data.

default

Is this the default coordinate system? Default FALSE.

clip

Should drawing be clipped to the panel ("on", default) or not ("off")?

roughness, bowing, n_passes

Sketch parameters for the frame. Gentle defaults suited to gridlines (0.5, 0.5, 2).

seed

Integer seed for reproducible wobble. NULL uses getOption("ggsketch.seed", 1L).

rough_grid, rough_ticks

Roughen the gridlines / axis ticks? Both default TRUE; set one to FALSE to leave that element crisp.

Details

The panel border is a plot-level theme element (not part of the coordinate system), so to roughen it as well, combine coord_sketch() with theme_sketch(rough_frame = TRUE) or set panel.border = element_sketch_rect(...).

See Also

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

Examples

Run this code
library(ggplot2)
# A rough frame under a plain (non-sketch) theme:
ggplot(mtcars, aes(wt, mpg)) +
  geom_sketch_point(seed = 1L) +
  coord_sketch(seed = 1L)

Run the code above in your browser using DataLab