View source: R/geom_kodom_line.R
| geom_kodom_line | R Documentation |
Draws one horizontal colored path per subject. Time maps to x, subject
identity maps to id (which the stat converts to integer lane positions on
the y axis), and a measured value maps to colour. The colour transitions
smoothly between consecutive observations via interpolated sub-segments.
geom_kodom_line(
mapping = NULL,
data = NULL,
stat = StatKodomLine,
position = "identity",
...,
sort_by = "none",
n_max = Inf,
show_points = TRUE,
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE
)
mapping |
Set of aesthetic mappings created by |
data |
A data frame. If |
stat |
The stat to use. Defaults to StatKodomLine. |
position |
Position adjustment, almost always |
... |
Other arguments passed to |
sort_by |
Lane ordering. One of |
n_max |
Maximum number of subjects to display. A random sample is taken
when exceeded. Default |
show_points |
If |
na.rm |
If |
show.legend |
Logical. Should this layer appear in the legend? |
inherit.aes |
If |
Lane ordering is controlled by sort_by. With many subjects, consider
suppressing y-axis labels via theme(axis.text.y = element_blank()).
A ggplot2 layer object.
Required aesthetics are shown in bold. size and linewidth are
intentionally independent: each controls a different graphical element.
x — time variable (numeric or Date)
id — subject identifier; determines lane position on the y axis
colour — color of both the connecting path and the point border
fill — point interior color for filled shapes (21–25); no effect on path
size — point size only; set to NA or 0 to suppress points
linewidth — path width only; does not affect observation points
alpha — transparency applied to both path and points
shape — point shape (default 19). Set to NA to suppress points.
stroke, linetype — point border width / path line type
library(ggplot2)
df <- data.frame(
subject_id = rep(1:5, each = 4),
time = rep(1:4, 5),
visit_month = rep(1:4, 5),
value = rep(1:4, 5),
hba1c = rep(1:4, 5),
arm = rep(c("Treatment", "Control"), c(12, 8))
)
ggplot(df, aes(x = time, id = subject_id, colour = hba1c)) +
geom_kodom_line(sort_by = "mean", n_max = 50) +
scale_colour_kodom() +
theme_kodom()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.