Skip to contents

Parameters to control the formatting and content of hovertext in roboplots.

Usage

set_hovertext(
  frequency = NULL,
  rounding = getOption("roboplot.rounding"),
  unit = "",
  text_col = NULL,
  format = NULL,
  extra = NULL
)

Arguments

frequency

Character. Determines the format of hovertemplate dates. One of "Annual", "Quarterly", "Monthly", "Weekly", "Daily", or NULL. Defaults to NULL, where roboplot() infers the format from d.

rounding

Double. Number of decimal places for hovertemplate values. Default is set with set_roboplot_options().

unit

Character. Unit displayed.

text_col

Symbol or character. Column used from d in a roboplot for labeling. If NULL, the column used for color (and, if given, pattern) is used for labels.

format

Function. A function for exact control of unit formatting.

extra

Character vector. Extra text displayed under any hovertext.

Value

A list of class roboplotr.set_hovertext

Examples

# Use to give hovertemplate specifications for `roboplot()` plots.
# Without specifying hovertext, `roboplot()` will construct it based
# on data from argument `d` of `roboplot()`, guessing frequency and using
# the argument `subtitle` as the unit of value. Control formatting with
# `frequency`, `rounding`, and `unit`.

d <- energiantuonti |>
  dplyr::filter(Alue %in% c("USA","Norja","Iso-Britannia"),
                Suunta == "Tuonti")

d |> roboplot(
  Alue, "Energian tuonti", "Miljoonaa euroa", "Lähde: Tilastokeskus.",
  hovertext = set_hovertext(
    frequency = "Monthly", rounding = 2, unit = "Milj. €"
    )
)
# Parameter 'extra' will be added to last line(s) of the hovertemplate, which # can be plain text or reference to `d` of the `roboplot()`, with d3 syntax. d |> roboplot( Alue, "Energian tuonti", "Milj. €", "Lähde: Tilastokeskus.", hovertext = set_hovertext("Annual", extra = "(%{x:|Q})") )