Parameters to customize labels displayed with roboplots traces. Use set_title, set_caption, set_legend, and set_axes with other labeling.
Arguments
- style
Character. Use 'none' for no labels (the default for all but pie plots). With
plot_type
"scatter" you can use 'auto' or 'last', withplot_type
"bar" you can use 'auto', 'outside' or 'mini', and withplot_type
pie you can use 'auto' or 'percent'.- color
Symbol. Use this to control the color of text outside the corresponding trace. The default is trace color. Color of text inside a trace is always controlled by roboplot to ensure accessibility.
- text_col
Symbol. The column used for labeling if something else than your trace values.
- size
Numeric. Font size of trace labels.
- ...
When using set_roboplot_options to set labels, you should provide any or all of set_labels(scatter, bar, pie), with 'scatter' controlling the global behavior of both lines and scatters. Do not use these when providing label styles inside roboplot, use
style
instead.
Examples
# Use `set_labels(style = "auto")` to automatically set the labels in bar plots
# inside or outside of bars according to how they fit.
d <- energiantuonti |> dplyr::filter(Alue == "USA")
d |> roboplot(Suunta, plot_type = "bar", plot_mode = "dodge", labels = set_labels("auto"))
# Use `style = "mini"` to label only the bars where the labels don't fit (ie. the
# smallest bars). You can omit using the `set_labels()`-function if you only wish
# to provide the state
d |> roboplot(Suunta, plot_type = "bar", plot_mode = "dodge", labels = "mini")
# `"inside"` and `"outside"` to force either state
d |> roboplot(Suunta, plot_type = "bar", plot_mode = "dodge", labels = "outside")
# Give `color` if you want to override the colors of labels outside the bars.
# `roboplot()` will always use its internal color paletter for the labels inside
# the bars to ensure accessibility. Give `size`to override the automatic font sizes
# plotly uses.
d |> roboplot(
Suunta,
plot_type = "bar",
labels = set_labels("auto", color = "black", size = 15)
)
# Works with horizontal bars, too
energiantuonti |>
dplyr::filter(time == max(time), Suunta == "Tuonti") |>
roboplot(
Suunta,
plot_type = "bar",
plot_mode = "horizontalfill",
plot_axes = set_axes(y = "Alue"),
labels = set_labels(style = "auto", size = 22)
)
# For scatter traces, use "auto" to highlight data points. You most likely will
# need to provide y-axis limits manually.
d |> roboplot(Suunta, labels = "auto", plot_axes = set_axes(ylim = c(-60, 700)))
# If you specify axis limits with `set_axes()` or `xaxis_ceiling`, `roboplot()`
# will not be able to detect x-axis limits correctly. Using xaxis_ceiling "default"
# should work.
d |> roboplot(Suunta, labels = "auto", xaxis_ceiling = "guess")
# Pies can handle only no labels, or percentage labels.
energiantuonti |>
dplyr::filter(time == max(time), Suunta == "Tuonti") |>
roboplot(Alue, plot_type = "pie")
# Set defaults with `set_roboplot_options()` by trace type.
set_roboplot_options(labels = set_labels(scatter = "auto", bar = "mini", pie = "none"))