apexcharter/examples/timeline.R

48 lines
941 B
R
Raw Permalink Normal View History

2020-02-12 16:37:47 +01:00
library(apexcharter)
data("presidential", package = "ggplot2")
2020-12-16 14:39:10 +01:00
# Basic (with formated date in tooltip)
2023-06-12 09:51:06 +02:00
apex(presidential, aes(x = name, start = start, end = end), "timeline") %>%
2020-12-16 14:39:10 +01:00
ax_tooltip(
x = list(
format = "yyyy"
)
)
2020-02-12 16:37:47 +01:00
# With groups
2023-06-12 09:51:06 +02:00
apex(
presidential,
aes(x = name, start = start, end = end, group = party),
"timeline"
)
2020-02-12 16:37:47 +01:00
# With groups but force position
2023-06-12 09:51:06 +02:00
apex(
presidential,
aes(x = name, start = start, end = end, group = party),
"timeline"
) %>%
ax_plotOptions(
bar = bar_opts(rangeBarGroupRows = TRUE)
) %>%
ax_xaxis(categories = unique(presidential$name))
2020-02-12 16:37:47 +01:00
# With custom colors
2023-06-12 09:51:06 +02:00
apex(
presidential,
aes(x = name, start = start, end = end, group = party),
"timeline"
) %>%
ax_plotOptions(
bar = bar_opts(rangeBarGroupRows = TRUE)
) %>%
ax_xaxis(categories = unique(presidential$name)) %>%
ax_colors_manual(list(
Democratic = "#00355f",
Republican = "#c51c22"
))