Skip to contents

Parameters to customize patterns in roboplots.

Usage

set_pattern(
  pattern = NULL,
  pattern_types = NULL,
  pattern_along = NULL,
  show_legend = TRUE,
  sep = ", "
)

Arguments

pattern

Symbol or string. Column from param d of a roboplot to use for the linetype of plot_type "scatter" or pattern of plot_type "bar". Not supported for pie charts.

pattern_types

Named character vector. Pattern types for all traces. Names must correspond to values in the column referenced by pattern. See [set_roboplot_options()] parameter dashtypesandpatternsfor options, or use ".other" if multiple traces are of the sameplot_type` and share the pattern.

pattern_along

Symbol or string. Column from param d of a roboplot along which the series should be continuous along. If set, and the plot_mode corresponding to all items in pattern is "line", roboplot will try to fill the series in such a way as to create a continuous line.

show_legend

Logical, named if vector. If any pattern(s) will have their own legend entries. If FALSE, only the first item in param 'pattern' will be in a roboplot's legend. If named, the must correspond to values in the column referenced by pattern.

sep

Character. The separator of color and pattern in legend labels. Default is ", ". Use NA if you want to omit the pattern label from legend, resulting only the roboplot() param color being the label.

Value

A list of class roboplotr.set_pattern

Examples

# You can use [set_pattern()] to just give the column name, but in that case
# you could just as well provide the column name by itself.
# Compare this:
energiantuonti |>
  dplyr::filter(Alue %in% c("Belgia","USA")) |>
  roboplot(
    Alue,
    pattern = Suunta
  )
#' # To this: energiantuonti |> dplyr::filter(Alue %in% c("Belgia","USA")) |> roboplot( Alue, pattern = set_pattern(Suunta) )
# Suppose you have a series where some values are predictions and some are # observations, you would have a gap in a line plot. d <- energiantuonti |> dplyr::filter(Alue == "Belgia", Suunta == "Tuonti") |> dplyr::mutate(Sarjatyyppi = ifelse( lubridate::year(time) == max(lubridate::year(time)), "Ennuste", "Toteuma" )) roboplot(d, Alue, pattern = Sarjatyyppi)
# Use the parameter `pattern_along` to provide the column along which the plot # should show a continous line. roboplot(d, Alue, pattern = set_pattern(Sarjatyyppi, pattern_along = time))
# Use the parameter `show_legend` to omit all patterns expect the first one # from the legend, and use the parameter `sep` to control the separator # between the `roboplot()` param `color` and `pattern` in the legend. roboplot(d, Alue, pattern = set_pattern( Sarjatyyppi, pattern_along = time, show_legend = FALSE, sep = " - " ))
# Or just use `sep` = NA to omit the pattern from the legend labels. roboplot(d, Alue, pattern = set_pattern( Sarjatyyppi, pattern_along = time, show_legend = FALSE, sep = NA ))
# Finally, control the patterns for linetypes and bars with the parameter # `pattern_types`, with a named vector containing either all the observations # in the column `pattern`, or ".other" as a catch-all category. energiantuonti |> dplyr::filter(Alue %in% c("USA", "Belgia", "Ruotsi"), Suunta == "Tuonti") |> roboplot(Alue, pattern = set_pattern(Alue, pattern_types = c( "USA" = "dash", ".other" = "dot" )))
# Bar plots use the pattern_types too, but they are different from the ones # used by line plots. If you get them wrong, `roboplot()` informs you which you # should be using. energiantuonti |> dplyr::filter(Alue %in% c("USA", "Belgia", "Ruotsi"), Suunta == "Tuonti") |> roboplot(Alue, plot_type = "bar", pattern = set_pattern(Alue, pattern_types = c( "Ruotsi" = "", ".other" = "x" )))