Skip to contents

A hand-drawn take on ggplot2::geom_sf(). Roughens the boundaries of sf geometry: (MULTI)POLYGON features are filled with a hole-aware hachure (or any fill_style), (MULTI)LINESTRING features become sketch paths, and (MULTI)POINT features become sketch points. One call draws whichever geometry types are present.

Usage

GeomSketchSfPolygon

geom_sketch_sf(
  mapping = ggplot2::aes(),
  data = NULL,
  ...,
  fill_style = "hachure",
  roughness = 1,
  bowing = 1,
  n_passes = 2L,
  seed = NULL,
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = FALSE
)

Arguments

mapping

Aesthetic mappings created by ggplot2::aes(), referring to columns of data (e.g. aes(fill = pop)). The geometry column is handled automatically - do not map it.

data

An sf or sfc object (required).

...

Other arguments passed on to the underlying layers.

fill_style

Fill style for polygons; see geom_sketch_polygon(). Default "hachure".

roughness, bowing, n_passes, seed

Sketch parameters; see geom_sketch_path().

na.rm

Remove missing values silently? Default FALSE.

show.legend, inherit.aes

Standard layer arguments. inherit.aes defaults to FALSE (as for geom_sf()).

Value

A list of ggplot2 layers (one per geometry kind present).

Details

Requires the sf package. Unlike geom_sf(), this does not integrate with coord_sf(); it plots in planar coordinates, so pre-project longitude/latitude data with sf::st_transform() for an undistorted map. The data argument must be given explicitly (an sf or sfc object); aesthetics in mapping refer to columns of that object.

Examples

library(ggplot2)
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
ggplot() +
  geom_sketch_sf(data = nc, aes(fill = AREA), seed = 1L) +
  scale_fill_viridis_c() +
  theme_void()