Set up an update menu for a plot
Arguments
A column from param "d" of call to
roboplot()
that will be used to create the buttons in the update menu. If the column is not a factor, it will be converted to one.- selected
The default selected button. Default is the first level of
buttons
.- position
The position of the update menu. Default is "topleft". Options are "topleft", "topright", "bottomleft", "bottomright".
- opacity
The opacity of the update menu background. Default is 0.9.
Value
A list of class roboplotr.set_updatemenu
that can be passed to the updatemenu
parameter of roboplot()
.
Examples
# For a long list of legend items, use `set_updatemenu()`.
energiantuonti |> roboplot(color = Suunta, updatemenu = set_updatemenu(Alue))
# Control position and default selection
energiantuonti |>
roboplot(color = Suunta,
updatemenu = set_updatemenu(Alue, selected = "Ruotsi", position = "topright"))
# `roboplot()` uses the `subtitle` parameter for hovertext unit labeling. If
# your updatemenu refers various units, you need to pass the correct labeling
# with `set_hovertext()`.
energiantuonti |>
dplyr::filter(Alue %in% c("USA", "EU-maat", "Belgia", "Ruotsi")) |>
dplyr::group_by(Alue, Suunta) |>
dplyr::mutate(indeksi = value / mean(value[lubridate::year(time) == 2015]) * 100,
Suunta = tolower(Suunta)) |>
dplyr::ungroup() |>
tidyr::pivot_longer(c(value, indeksi), names_to = "Tiedot") |>
dplyr::mutate(Tiedot = ifelse(Tiedot == "value", "Arvo", "Indeksi (2015 = 100)")) |>
tidyr::drop_na() |>
dplyr::mutate(hoverlabel = stringr::str_glue("{Alue}, {Suunta}\n{Tiedot}")) |>
roboplot(
Alue,
"Energiantuonti",
pattern = set_pattern(Suunta, sep = ": "),
updatemenu = set_updatemenu(Tiedot, position = "topright"),
hovertext = set_hovertext(unit = "", text_col = hoverlabel)
)