| scale_x_kodom_periodic | R Documentation |
This is a convenience wrapper around ggplot2::scale_x_continuous() that
enforces limits = c(0, period) and uses oob = scales::oob_keep.
scale_x_kodom_periodic(period = 12, breaks = 1:period, ...)
period |
The length of one complete cycle (e.g. |
breaks |
Passed to |
... |
Additional arguments passed to |
Why is this necessary? To make exactly one cycle span exactly one
360-degree rotation in coord_polar, the scale limits must be set to the
period length (e.g., c(0, 12)). However, standard ggplot2 scale_x_continuous
will drop any data outside those limits. By setting oob = scales::oob_keep,
we instruct ggplot2 to keep the data that exceeds the period. coord_polar
then natively wraps those out-of-bounds values around the circle, creating
beautiful, continuous Archimedean spirals!
A ggplot2::scale_x_continuous() object.
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 = visit_month, id = subject_id, colour = hba1c)) +
geom_kodom_periodic(period = 12) +
scale_x_kodom_periodic(period = 12, labels = month.abb) +
scale_y_kodom_periodic() +
coord_kodom_periodic() +
theme_kodom_periodic()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.