Adds one or more reference lines or segments to a plot. Dispatches to the appropriate ggplot2 geom based on the parameters supplied:
Usage
mark_rule(
plot,
mapping = NULL,
data = NULL,
xintercept = NULL,
yintercept = NULL,
slope = NULL,
intercept = NULL,
x = NULL,
xend = NULL,
y = NULL,
yend = NULL,
color = NULL,
linetype = NULL,
linewidth = NULL,
...,
rasterize = FALSE,
rasterize_dpi = 300,
rasterize_dev = "cairo"
)Arguments
- plot
A plotit object
- mapping
Optional aesthetics for data-driven segments (
x/xend/y/yend); layout tables bind them automatically.- data
Optional data for segment mode: one segment per row. Accepts a data.frame or a
~tablereference into graph data.- xintercept
x-intercept for vertical line(s)
- yintercept
y-intercept for horizontal line(s)
- slope
Line slope for abline
- intercept
Line intercept for abline
- x
Start x coordinate(s) for segment
- xend
End x coordinate(s) for segment
- y
Start y coordinate(s) for segment
- yend
End y coordinate(s) for segment
- color
Line colour (default
"grey50", the unified soft neutral; ggplot2's black is restored by passingcolor = "black"). The British spellingcolouris still accepted through....- linetype
Line type
- linewidth
Line width in mm (default 0.5).
- ...
Other arguments passed to the underlying geom
- rasterize
If
TRUE, rasterize viaggrastr::rasterise().- rasterize_dpi
DPI for rasterization (default 300).
- rasterize_dev
Graphics device for rasterization (default
"cairo").
Details
xintercept→ ggplot2::geom_vlineyintercept→ ggplot2::geom_hlineslope+intercept→ ggplot2::geom_ablinex/xend/y/yend→ ggplot2::geom_segment
Dispatch priority: vline/hline > abline > segment.
Examples
plotit(iris, encode(x = Sepal.Width, y = Sepal.Length)) |>
mark_rule(xintercept = 3, color = "red", linetype = "dashed")
# Data-driven segments: network edges from a layout_* transform
e <- data.frame(source = c("a", "a", "b"), target = c("b", "c", "c"))
as_graph(e) |>
plotit() |>
layout_force(seed = 1) |>
mark_point(data = ~nodes) |>
mark_rule(data = ~edges, color = "grey70")