| a11y_ggplot2_line | R Documentation |
A minimal wrapper for a multi-line chart with accessibility features using ggplot2::ggplot2. Provides a high-contrast color palette, distinct marker shapes, and a minimal theme by default.
a11y_ggplot2_line(
data,
x,
y,
group = NULL,
accessible_colors = NULL,
marker_shapes = NULL,
line_width = 1,
marker_size = 2,
legend_title = NULL,
...
)
data |
Data frame |
x |
Column name for the x-axis (unquoted) |
y |
Column name for the y-axis (unquoted) |
group |
(optional) Column name for grouping lines (unquoted) |
accessible_colors |
(optional) Character vector of colors for the palette |
marker_shapes |
(optional) Numeric vector of point shapes, e.g.
|
line_width |
(optional) Line width (default: |
marker_size |
(optional) Point size (default: |
legend_title |
(optional) Title for the legend |
... |
Additional arguments passed to |
A ggplot2::ggplot() object
# Simple line chart (no grouping)
df <- data.frame(year = 2020:2024, value = c(10, 14, 13, 17, 20))
a11y_ggplot2_line(
data = df, x = year, y = value,
title = "Trend"
)
# Grouped line chart
df2 <- data.frame(
year = rep(2020:2024, 2),
value = c(10, 14, 13, 17, 20, 8, 9, 11, 12, 15),
grp = rep(c("A", "B"), each = 5)
)
a11y_ggplot2_line(
data = df2, x = year, y = value,
group = grp, title = "Trend by Group"
)
# With legend title and additional ggplot2 layers
p <- a11y_ggplot2_line(
data = df2, x = year, y = value, group = grp,
legend_title = "Group",
title = "Trend by Group"
)
p + ggplot2::geom_hline(yintercept = 12, linetype = "dashed") +
ggplot2::labs(
x = "Year", y = "Value",
subtitle = "With custom axis labels"
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.