Learn R Programming

ggsketch (version 2.0.0)

GeomSketchArrow: Sketchy content-aware arrows

Description

Draws a hand-drawn arrow from (x, y) to (xend, yend), with an optional handwriting label at the source. It is "content-aware" in three ways:

Usage

GeomSketchArrow

geom_sketch_arrow( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., curvature = "auto", roughness = 1, bowing = 1, n_passes = 2L, seed = NULL, arrow_length = NULL, arrow_angle = 25, arrow_type = "open", arrow_head = NULL, ends = "last", family = NULL, label_gap = 0.012, na.rm = FALSE, show.legend = FALSE, inherit.aes = TRUE )

Value

A ggplot2 layer object.

Arguments

mapping

Aesthetic mappings created by ggplot2::aes(). Requires x, y, xend, yend; label is optional.

data

Data with one row per arrow.

stat

Statistical transformation. Default "identity".

position

Position adjustment. Default "identity".

...

Other arguments passed on to the layer.

curvature

Shaft bend. "auto" (default) picks a gentle bow; a number sets it explicitly (0 straight, positive/negative bow to either side).

roughness

Non-negative roughness (0 = clean). Default 1.

bowing

Non-negative bowing multiplier. Default 1.

n_passes

Number of stroke passes. Default 2.

seed

Integer seed. NULL uses getOption("ggsketch.seed", 1L).

arrow_length

Arrowhead length in inches. NULL (default) adapts it to the shaft length.

arrow_angle

Half-angle of the arrowhead in degrees. Default 25.

arrow_type

"open" (default) draws a two-stroke V; "closed" draws a filled rough triangle. Superseded by arrow_head; kept for back-compat.

arrow_head

Arrowhead style, one of sketch_arrowheads(): "triangle_open", "triangle_filled", "barb" (swept harpoon barbs), "fishtail" (forked swallowtail), "dot" (a blob) or "bar" (a perpendicular tick). NULL (default) derives it from arrow_type.

ends

Which end(s) carry a head: "last" (default), "first" or "both" (a double-headed arrow).

family

Font family for the label. Defaults to the same family as theme_sketch() (getOption("ggsketch.base_family", ""), i.e. the device default), so the label matches the plot's other text; set options(ggsketch.base_family = "auto") for a handwriting face, or pass an explicit family here.

label_gap

Gap between the label anchor and the source point, in npc. Default 0.012.

na.rm

Remove missing values silently? Default FALSE.

show.legend

Logical; include in legend? Default FALSE.

inherit.aes

Inherit aesthetics from the plot? Default TRUE.

Details

  • the shaft curvature defaults to an automatic, pleasing bow whose side follows the direction of travel (curvature = "auto");

  • the arrowhead is roughened and oriented to the curve's end tangent, so it always points at the target however the shaft bends;

  • the label justifies itself away from the target, so it never sits under the shaft.

For one-off annotations, annotate_sketch_arrow() is the easiest entry point.

See Also

Other sketch-geoms: GeomSketchAbline, GeomSketchBoxplot, GeomSketchBracket, GeomSketchCallout, GeomSketchChicklet, GeomSketchCol, GeomSketchContourFilled, GeomSketchCurve, GeomSketchDotplot, GeomSketchDumbbell, GeomSketchEdge, GeomSketchEllipse, GeomSketchEngrave, GeomSketchGantt, GeomSketchHex, GeomSketchLine, GeomSketchLinerange, GeomSketchLollipop, GeomSketchMarkCircle, GeomSketchMarkHull, GeomSketchPath, GeomSketchPoint, GeomSketchPolygon, GeomSketchRect, GeomSketchRibbon, GeomSketchRug, GeomSketchSegment, GeomSketchSfPolygon, 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(), 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_qq(), geom_sketch_quantile(), geom_sketch_rose(), geom_sketch_sunburst(), geom_sketch_text(), sketch_graph()

Examples

Run this code
library(ggplot2)
ggplot(mtcars, aes(wt, mpg)) +
  geom_sketch_point(seed = 1L) +
  annotate_sketch_arrow(x = 4.5, y = 30, xend = 5.25, yend = 18,
                        label = "heavy & thirsty", seed = 2L) +
  theme_sketch()

Run the code above in your browser using DataLab