library(SveltePlots)
data("purchases")
sp(
data = purchases, type = "line",
mapping = spaes(x = date, y = revenue_roll, group = age),
colors = c("red", "green", "blue"),
combine_same_groups = TRUE
) |>
sp_add_series(
data = purchases,
mapping = spaes(x = date, y = revenue, group = age),
type = "points",
alpha = 0.4,
tooltip = FALSE,
include_legend = FALSE
) |>
sp_add_series(
data = purchases[purchases$revenue == max(purchases$revenue), ],
mapping = spaes(x = date, y = revenue, group = age),
type = "points",
size = 5,
tooltip = FALSE
) |>
sp_add_segments(
x_start = "2000-01-12", x_end = "2000-01-17",
y_start = "auto", y_end = "auto",
type = "rect",
opacity = 0.2,
background_color = "black",
text_color = "white",
show_legend = TRUE,
legend_text = "Highest Revenue Day",
tooltip = "Revenue: $13179"
) |>
sp_add_arrows(
x_start = c("2000-03-01", "2000-03-01"), x_end = c("2000-01-15", "2000-01-15"),
y_start = c(8000, 12000), y_end = c(10000, 13000),
arrow_head = c(0, 0),
size = c(200, 200),
curvature = c(0.2, 0.4),
direction = c("downward", "downward"),
color = c("black", "black"),
arrow_head_type = c("triangle", "triangle")
) |>
sp_add_text(
x = c("2000-02-01", "2000-02-20"),
y = c(12500, 8500),
text = c(
"This was the highest revenue day",
"Window of Some Event Happening"
)
)
Run the code above in your browser using DataLab