Parameters to customize caption defaults.
Arguments
- text
Character. The text used in the template (make sure the template has the parameter
text
).- ...
Other parameters to be passed to template.
- template
Character. Template for
stringr::str_glue()
used to parse the caption with the given parameters.- xref
Character. Either "container" or "plot". Determines if the caption is anchored to the plot or the container edge. Ignored for
robotable()
androbomap()
.
Examples
# Used to define how captions are constructed inside `roboplot()`. The used
# parameters are used inside stringr::str_glue() to parse a caption
# string. You can skip using `set_caption()` simply by giving a character string.
# You can provide the template here, or use the one defined globally with
# `set_roboplot_options()`.
d <- energiantuonti |> dplyr::filter(Alue == "USA",Suunta == "Tuonti")
d |> roboplot(Alue,"Energian tuonti Yhdysvalloista","Milj. €",
caption = "Tilastokeskus")
# Anchor the caption to the left edge of the container instead of the plot with
# `xref`. You probably want to do the same for title, but you don't have to.
d |>
roboplot(Alue,
title = set_title("Energian tuonti Yhdysvalloista", xref = "container"),
caption = set_caption("Tilastokeskus", xref = "container")
)
# Override the global template with function parameters and provide
# parameters for it. The example is unnecessarily complicated, but gives the
# idea how this could work.
d |>
roboplot(Alue, "Energy import","Million euros",
caption =
set_caption(
prepend = "(Canada)",
append = paste0("(Customs Finland, International trade ",
"statistics;<br>Radiation and Nuclear Safety ",
"Authority; Gasum LLC)"),
caption = "Statistics Finland",
template = "{prepend}.<br>Source: {caption}.<br>{append}."
)
)
# If you need to make manual changes repeatedly, you are probably better off
# using `set_roboplot_options()` to change the defaults to something more sensible.
set_roboplot_options(
caption_template = "Source: {text}.",
)
d |> roboplot(Alue,"Energy import from Canada","M€", "Statistic Finland")
# Revert to defaults:
set_roboplot_options(reset = TRUE)
# Finally, don't use a caption by providing NA.
d |> roboplot(Alue, "Energin tuonti Kanadasta", "Milj €", caption = NA)