library(SveltePlots)
library(dplyr)
library(lubridate)
data("economics")
data("confidence_intervals")
data("purchases")
sp(
data = economics,
type = "line",
mapping = spaes(x = date, y = unemploy),
colors = "red"
) %>%
sp_add_series(
data = economics,
mapping = spaes(x = date, y = pce),
type = "line",
colors = "green"
) %>%
sp_add_series(
data = economics,
mapping = spaes(x = date, y = psavert),
type = "line",
colors = "blue"
)
data("gapminder")
gapminder <- gapminder %>%
dplyr::mutate(
country = as.character(country),
year = lubridate::ymd(paste0(year, "-01-01"))
)
sp <- SveltePlots::sp(
data = gapminder %>%
dplyr::group_by(year, continent) %>%
dplyr::summarise(
lifeExp = mean(lifeExp)
) %>%
dplyr::ungroup(),
mapping = spaes(x = year, y = lifeExp, group = continent),
type = "line",
combine_same_groups = FALSE
) %>%
sp_add_series(
data = gapminder %>%
dplyr::filter(country == "Germany"),
mapping = spaes(x = year, y = lifeExp, group = country),
type = "line",
colors = "gold"
) %>%
sp_add_series(
gapminder %>%
dplyr::filter(country == "Chile"),
mapping = spaes(x = year, y = lifeExp, group = country),
type = "line",
colors = "silver"
) %>%
sp_add_series(
gapminder %>%
dplyr::filter(country == "Chile"),
mapping = spaes(x = year, y = lifeExp, group = country),
type = "points",
size = 3,
tooltip = FALSE
)
sp(
data = purchases,
mapping = spaes(x = date, y = revenue_roll, group = age),
type = "line",
colors = c("red", "green", "blue"),
combine_same_groups = FALSE
) %>%
sp_add_series(
data = purchases,
mapping = spaes(x = date, y = revenue, group = age),
type = "points",
alpha = 0.4,
tooltip = 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
)
Run the code above in your browser using DataLab