Skip to contents

geom_hachure() shows the shape of the land with hachures: fine ink lines that run down each slope, as on engraved maps. The lines are heavier where the ground is steeper, and level ground stays bare. The lines start on the highest ground and stay an even distance apart.

Usage

geom_hachure(
  elevation,
  colour = "#7A4A2A",
  alpha = 0.85,
  linewidth = c(0.12, 0.6),
  separation = 0.5,
  min_slope = 3,
  steep_slope = 35,
  exaggeration = 1,
  light = NULL,
  light_strength = 0.6,
  mask = NULL,
  clip = NULL,
  smoothing = 0.4,
  min_length = 1,
  monochrome = FALSE,
  seed = NULL
)

Arguments

elevation

A single-layer SpatRaster of heights in metres, from the terra package.

colour

Colour of the lines.

alpha

Opacity of the lines.

linewidth

The widths of the lightest and heaviest lines, as a vector of two numbers.

separation

Distance between neighbouring lines, in millimetres.

min_slope

The gentlest slope that gets lines, in degrees.

steep_slope

The slope at which lines reach their full weight, in degrees.

exaggeration

A number that multiplies the heights before the slopes are measured, or "auto" to choose the number from the land in view. The default, 1, uses the true slopes. See the section on map scale.

light

The compass bearing that the light comes from, in degrees clockwise from north: 0 is north, 90 is east, and 315 is north-west. If NULL, the default, the light comes from above and the direction of a slope has no effect. See the section on illumination.

light_strength

How much the light changes the weight of the lines, between 0 (no change) and 1. Only used when light is set.

mask

An sf or sfc object of polygons that must get no lines. If NULL, the default, every cell with a height can get lines. See the section on masks.

clip

An sf or sfc object of polygons. Only the cells inside them can get lines. If NULL, the default, the layer does not clip the lines. See the section on masks.

smoothing

How much to smooth the terrain before tracing, as a distance in millimetres. Use 0 for no smoothing.

min_length

The shortest line to keep, in millimetres.

monochrome

If TRUE, draw in the grey of the same lightness as colour.

seed

A single integer that fixes where the lines start. If NULL, the layer chooses a seed at random when you create the layer.

Value

A list holding a ggplot2 layer and a default ggplot2::coord_sf(), to be added to a plot.

Details

ggwatercolor traces the lines when the device draws the plot. For this reason, separation, smoothing, and min_length are lengths on the page in millimetres. The lines keep the same spacing at any map scale.

elevation must hold heights in metres. Cells with missing values get no lines, so set the sea to NA to keep lines on the land, or give the land as clip. ggwatercolor does not download elevation data. The elevatr and geodata packages can get elevation data for most places.

The layer extends the plot to the extent of elevation. To show a smaller area, set limits with ggplot2::coord_sf().

Illumination

By default the weight of a line depends only on the steepness of the ground, as if the light came from directly above. Set light to a compass bearing to light the land from that side. Lines are then thinner on slopes that face the light and heavier on slopes that face away. Mapmakers usually put the light in the north-west, light = 315. The bearing assumes that north is at the top of the map.

Map scale

min_slope and steep_slope are slopes of the ground, and the layer measures them at the resolution of the page. On a map of a large area, one millimetre covers many kilometres, and slopes measured across that distance are gentle. With the default settings, such a map gets few lines.

exaggeration corrects this. It multiplies the heights before the layer measures the slopes, as on a relief model. With exaggeration = "auto", the layer chooses the value from the land in view, so that the steepest ground reaches steep_slope. A map of a large area also needs more smoothing, about 1 millimetre, to keep the lines long.

Masks

The layer draws lines on every cell of elevation that has a height. To show the relief of some land only, give the other land as mask. The cells under the mask get no lines. For example, a map of Alaska can mask Canada and Russia. The mask does not change the limits of the plot.

clip is the opposite of mask. Give the land that can get lines, and the cells outside it get none. Use clip when the sea in elevation has heights and not missing values. Such a sea gets lines along the coast, most of all with smoothing and exaggeration, because the smoothing spreads the heights of the coast into the sea. mask and clip can be used together.

The work grows with the size of the panel and shrinks as separation grows. A full-page map can take a few seconds to draw.

See also

Examples

library(ggplot2)

maui <- hawaii[hawaii$island == "Maui", ]
elevation <- terra::crop(hawaii_elevation(), terra::vect(maui))

ggplot() +
  geom_hachure(elevation, seed = 1) +
  geom_sf_wash(data = maui, seed = 1) +
  geom_sf(data = maui, fill = NA) +
  theme_paper_void()


# Light the land from the north-west
ggplot() +
  geom_hachure(elevation, light = 315, seed = 1) +
  geom_sf_wash(data = maui, seed = 1) +
  geom_sf(data = maui, fill = NA) +
  theme_paper_void()


# Show the relief of one island only. The other islands are the mask.
ggplot(hawaii) +
  geom_hachure(
    hawaii_elevation(),
    mask = hawaii[hawaii$island != "Hawaii", ],
    seed = 1
  ) +
  geom_sf(fill = NA) +
  theme_paper_void()


# Keep the lines inside the land when the sea has heights
sea_level <- terra::subst(elevation, NA, 0)
ggplot() +
  geom_hachure(sea_level, clip = maui, smoothing = 1, seed = 1) +
  geom_sf(data = maui, fill = NA) +
  theme_paper_void()