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
)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.
NULLusesgetOption("ggsketch.seed", 1L).- rough_grid, rough_ticks
Roughen the gridlines / axis ticks? Both default
TRUE; set one toFALSEto 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(...).
Examples
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)
