mark_rect() draws one rectangle per row, spanning xmin..xmax by
ymin..ymax (ggplot2's geom_rect()). Unlike mark_tile() (a centre and
a size), it takes the corner bounds, so an infinite bound reaches the panel
edge: xmin = -Inf, xmax = Inf shades a full-width band. fill fills
(default "grey35") and color outlines; a color given without any
fill fills the rectangle instead, as for mark_tile().
annotate()("rect", ...) draws a one-off rectangle.
Arguments
- plot
- ...
Encodings (tidy-eval):
xmin,xmax,ymin,ymax(+fill,color,alpha,linewidth,pattern).- 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.- 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).- 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.
Value
The modified PlotSpec.
Examples
recs <- data.frame(
start = c(1, 4, 7), end = c(3, 5, 10),
party = c("A", "B", "A")
)
vplot(recs) |>
mark_rect(xmin = start, xmax = end, ymin = 0, ymax = 1, fill = party)
