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 layer draws whichever geometry types are present, geometry collections included.

Usage

GeomSketchSfPolygon

GeomSketchSf

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

Arguments

mapping

Aesthetic mappings created by ggplot2::aes(), referring to columns of the data (e.g. aes(fill = pop)). The geometry column is found automatically; map geometry only to pick a different one.

data

An sf object, or a bare sfc geometry column. NULL (the default) uses the plot's data.

stat, position

The statistical transformation and position adjustment; as for ggplot2::geom_sf().

...

Other arguments passed on to ggplot2::layer_sf(): fixed aesthetics such as colour = "navy" or linewidth = 0.3, and the fill parameters hachure_angle, hachure_gap (device inches; NULL picks 15% of each polygon's smaller drawn extent, clamped to [0.04, 0.15] inches), fill_weight, fill_roughness and fill_seed (see geom_sketch_polygon()).

fill_style

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

roughness, bowing, n_passes, seed

Sketch parameters; see geom_sketch_path(). Points are roughened at half roughness.

na.rm

Remove missing values silently? Default FALSE.

show.legend

Logical, or one of "point", "line" or "polygon" to choose the kind of legend key, as for geom_sf().

inherit.aes

If TRUE (the default, as for geom_sf()), combine the layer's mapping with the plot's.

Value

A list holding the layer and a default coord, a coord_sketch_sf() (a ggplot2::coord_sf() that draws the graticule as the theme draws its grid lines), as geom_sf() returns; add it to a plot with +.

Details

Requires the sf package. Like geom_sf() the layer is built on ggplot2::stat_sf() and ggplot2::coord_sf(): it finds the geometry column of the plot's or the layer's data on its own (so ggplot(my_sf) + geom_sketch_sf() works), the map is drawn in the data's coordinate reference system or the one given to coord_sf(crs = ), and coord_sf() draws the graticule. Under another coord, such as coord_fixed(), the geometry is drawn unprojected in its own units.

The layer's default coord is a coord_sketch_sf() that draws the graticule hand-drawn when the theme's major grid lines are element_sketch_line()s, as under theme_sketch(rough_frame = TRUE), and crisp otherwise. To set a projection and keep that, add coord_sketch_sf(crs = ) rather than coord_sf(crs = ); coord_sketch_sf() also roughens the graticule under any theme.

Unmapped aesthetics default per geometry: polygons take a grey hachure with a dark outline, lines and points the defaults of geom_sketch_path() and geom_sketch_point().

See also

Other sketch-geoms: GeomSketchAbline, GeomSketchArrow, GeomSketchBoxplot, GeomSketchBracket, GeomSketchCallout, GeomSketchChicklet, GeomSketchCol, GeomSketchContourFilled, GeomSketchCurve, GeomSketchDotplot, GeomSketchDumbbell, GeomSketchEdge, GeomSketchEllipse, GeomSketchEngrave, GeomSketchGantt, GeomSketchHex, GeomSketchLine, GeomSketchLinerange, GeomSketchLollipop, GeomSketchMarkCircle, GeomSketchMarkHull, GeomSketchNote, GeomSketchPath, GeomSketchPoint, GeomSketchPolygon, GeomSketchRect, GeomSketchRibbon, GeomSketchRug, GeomSketchSegment, GeomSketchSlope, GeomSketchSmooth, GeomSketchSpoke, GeomSketchTextRepel, GeomSketchViolin, StatSketchBeeswarm, StatSketchCalendar, StatSketchDensityRidges, StatSketchFunnel, StatSketchPie, StatSketchPyramid, StatSketchRadar, StatSketchStream, StatSketchTreemap, StatSketchWaffle, StatSketchWaterfall, annotate_sketch(), annotate_sketch_arrow(), annotate_sketch_callout(), annotate_sketch_highlight(), annotate_sketch_note(), geom_sketch_alluvial(), geom_sketch_arc_diagram(), geom_sketch_bin2d(), geom_sketch_bump(), geom_sketch_chord(), geom_sketch_contour(), geom_sketch_count(), geom_sketch_dendrogram(), geom_sketch_density(), geom_sketch_density2d(), geom_sketch_ecdf(), geom_sketch_function(), geom_sketch_histogram(), geom_sketch_jitter(), geom_sketch_marimekko(), geom_sketch_mosaic(), geom_sketch_parallel(), geom_sketch_point_interactive(), geom_sketch_qq(), geom_sketch_quantile(), geom_sketch_rose(), geom_sketch_sunburst(), geom_sketch_text(), sketch_graph()

Examples

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


# coord_sf() projects the map
ggplot(nc[1:20, ]) +
  geom_sketch_sf(fill_style = "cross_hatch", seed = 2L) +
  coord_sf(crs = 32119)


# coord_sketch_sf() projects it too, with a hand-drawn graticule
ggplot(nc[1:20, ]) +
  geom_sketch_sf(fill_style = "cross_hatch", seed = 2L) +
  coord_sketch_sf(crs = 32119, seed = 2L)