mark_segment() draws a straight line from (x, y) to (xend, yend) per row.
mark_curve() bends that line into an arc (ggplot2's geom_curve()).
mark_spoke() draws a segment from (x, y) in the direction angle
(radians) with length radius, both in data units (ggplot2's
geom_spoke()): a vector field.
Usage
mark_segment(
plot,
...,
position = "identity",
auto = FALSE,
blend = NULL,
effects = list(),
sketch = NULL,
data = NULL
)
mark_curve(
plot,
...,
curvature = 0.5,
angle = 90,
ncp = 5,
position = "identity",
blend = NULL,
effects = list(),
sketch = NULL,
data = NULL
)
mark_spoke(
plot,
...,
position = "identity",
blend = NULL,
effects = list(),
sketch = NULL,
data = NULL
)Arguments
- plot
- ...
Encodings (tidy-eval):
x,y,xend,yend(+color,linewidth,linetype,alpha);mark_spoke()takesangleandradiusin place ofxend,yend. A mappedlinewidthgives each segment its own width – seescale_linewidth().- position
Position adjustment: a string —
"identity"(default),"nudge","stack","fill","dodge","dodge2","jitter","jitterdodge","sina"— or a parameterised position object such asposition_dodge()orposition_stack(). Every mark takes"identity"and"nudge"."stack"/"fill"work on bars, areas, points, text and labels (so a label can sit on its stacked bar);"dodge"/"dodge2"on bars, points, text, labels, error bars, line/point ranges, cross-bars, box plots, violins and slab-intervals (so error bars dodge over dodged bars);"jitter"on points, text and labels;"jitterdodge"and"sina"on points. A position a mark does not support is an error naming the ones it does.- auto
For
mark_point(),mark_line(),mark_step(),mark_segment(), andmark_edges(), whenTRUEand the layer has very many rows, automatically render it as a datashaded density raster (seemark_datashade()) instead of individual vector marks: points bin into a density grid (vellum::datashade()), dense lines/steps rasterise as connected polylines (vellum::datashade_lines()), and segments/edges as independent segments (vellum::datashade_segments()). The datashaded line/segment output isdynspread-ed so thin marks stay visible (see thespreadargument ofmark_datashade()). The fallback is skipped under a warped coordinate system (coord_polar()/coord_trans()), which draws the vector marks instead.- blend
Optional blend mode for compositing this layer against what is already drawn beneath it (the panel and earlier layers), one of the CSS
mix-blend-modenames, e.g."multiply","screen","darken". The whole layer composites as one isolated group (not per element).- effects
A list of layer render effects applied to the mark at draw time —
glow(),outline(), andshadow(). Available on stroked and point marks.- sketch
A
sketch()spec giving this layer a hand-drawn look (wobbly outlines, hachure fills),NA/FALSEto force it crisp (overriding a plot-widetheme_sketch()), orNULL(default) to inherit. Geometry marks accept it; text, raster, hex and datashade marks do not.- data
Optional layer data frame; overrides the plot data for this layer.
- curvature
For
mark_curve(), the amount of bend:0is straight,1a half circle; negative values bend the other way (ggplot2's convention: positive bends to the right, travelling from start to end).- angle
For
mark_curve(), where the apex of the bend sits, in degrees between 0 and 180:90(default) is symmetric, smaller values move it towards the start and larger towards the end.- ncp
For
mark_curve(), the number of control points (more give a smoother curve; default5).
Value
The modified PlotSpec.
Details
A curve bends in the panel's own frame (its x and y spans scaled to the same length), so on a panel that is not square the arc stretches with the panel; ggplot2 bends in device space instead.
Examples
d <- data.frame(x = 1, y = 1, xend = 5, yend = 4)
vplot(d) |> mark_segment(x = x, y = y, xend = xend, yend = yend)
vplot(d) |> mark_curve(x = x, y = y, xend = xend, yend = yend)
# a vector field
g <- expand.grid(x = 1:8, y = 1:8)
g$angle <- atan2(g$y - 4.5, g$x - 4.5)
vplot(g) |> mark_spoke(x = x, y = y, angle = angle, radius = 0.4)
