fill_crosshatch() builds a grid::pattern() fill value that renders two
mirror-symmetric hatch lines, at angle and -angle, forming an "X"
inside each tile.
Usage
fill_crosshatch(
color = "black",
angle = 45,
spacing = 0.1,
aspect = NULL,
linewidth = 1,
extend = "repeat"
)Arguments
- color
One or more line colours. A vector of length 2 colours the two lines independently; a single colour (the default) colours both the same, matching the original behaviour. Longer vectors are recycled to length 2. Default
"black".- angle
Hatch angle in degrees, measured counterclockwise from the positive x-axis. Default
45.- spacing
Baseline tile size, as a fraction of the target's bounding box. Must be a positive number. Default
0.1.- aspect
Width-to-height ratio of the target polygon's bounding box. Must be a positive number, or
NULL(the default) to resolve it automatically from the real target's own bounding-box aspect ratio atdraw()time – see the fill class. Passing a fixed number instead computes the pattern once, immediately, against that value only.- linewidth
Line width. Must be a positive number. Default
1.- extend
Passed to
grid::pattern(). Default"repeat".
Value
A pattern object as returned by grid::pattern(), suitable for
use as the fill argument to grid::gpar().
Details
It shares fill_hatch()'s tile-shape technique: both lines are drawn as
the two corner-to-corner diagonals of a single rectangular tile (rather
than at an arbitrary baked-in slope), so both tile seamlessly under
extend = "repeat", and the tile's width/height ratio – not the
diagonals' own coordinates – determines the rendered angle. See
fill_hatch()'s details for why this matters.
Because both lines share one tile shape, they are only perpendicular
when angle = 45 (the classic crosshatch look); for other angles the two
lines are symmetric about the horizontal axis but not at right angles to
each other. Genuinely perpendicular hatching at an arbitrary angle would
need two differently-shaped tiles layered as separate fills, which this
function does not attempt.
At angle a multiple of 90 degrees, the two mirrored diagonals would
coincide, so this case is handled separately by drawing a horizontal line
and a vertical line instead (a simple grid).
Examples
draw(shape_circle(fill = fill_crosshatch(angle = 30)))
# at a multiple of 90 degrees, the mirrored diagonals would coincide,
# so a plain horizontal/vertical grid is drawn instead
draw(shape_circle(fill = fill_crosshatch(angle = 0, spacing = 0.15)))
# only angle = 45 gives genuinely perpendicular lines; other angles are
# symmetric about the horizontal axis but not at right angles
draw(shape_circle(fill = fill_crosshatch(angle = 20, spacing = 0.12)))
# a two-colour vector colours the two lines independently
draw(shape_circle(
fill = fill_crosshatch(color = c("steelblue", "tomato"), angle = 45)
))