Skip to contents

Parameters to customize fonts in various roboplotr contexts.

Usage

set_font(
  font = "Arial",
  fallback = NULL,
  size = NULL,
  color = NULL,
  bold_title = T,
  type = NULL
)

Arguments

font

Character. One of your system fonts if systemfonts package is available, or "Arial", "Verdana", "Tahoma", "Trebuchet", "Times New Roman", "Georgia", "Garamond", "Courier New", "Brush Script MT", a Google font, or a path to an .otf or .ttf file.

fallback

Character. Only used when a file path is used with font. Fallback font when the defined font is unavailable. Especially concerns image downloads.

size

Numeric. Font size.

color

Character. Must be a hexadecimal color or a valid css color.

bold_title

Logical. Only used for font of type title. Determines if the title is bolded.

type

Character. One of "main", "title" or "caption".

Value

A list of class roboplot.set_font

Examples

# Used to set fonts used by `roboplotr` functions. You can designate various
# specifications. You must provide a web-safe fallback (as accepted by `roboplotr`,
# see `font`) font if an actual filepath is provided for 'path'.

set_roboplot_options(
  caption_template = "Lähde: {text}!!",
  font_title = set_font(size = 17, font = "Tahoma", bold = TRUE),
  font_main =  set_font(
    size = 11,
    font = system.file("www","fonts","bladerunner.TTF", package = "roboplotr"),
    fallback = "Verdana",
    color = "darkred",
    type = "main"),
  font_caption = set_font(color = "green")
)

d <- energiantuonti |> dplyr::filter(Alue == "USA",Suunta == "Tuonti")

d |> roboplot(Alue,"Energian tuonti Yhdysvalloista","Milj. €","Tilastokeskus")
# Valid Google Fonts work as well. set_roboplot_options(font_title = set_font(font = "Exo")) # Note that `plotly`'s own downloadImage method does not support external fonts. # It can only use the fonts the browser has available. Use `set_artefacts()` # `roboplot()` to automate their creation if you need static images with external fonts. if (FALSE) { # \dontrun{ # Create a html file with `roboplot()`. d |> roboplot( color = Alue, title = "Energian tuonti Yhdysvalloista", subtitle = "Milj. €", caption = "Tilastokeskus", artefacts = set_artefacts(artefacts = c("html", "png"), filepath = tempdir()) ) # The html has proper fonts, but files exported from modebar will not. utils::browseURL(paste0(tempdir(),"/energian_tuonti_yhdysvalloista.html")) # The images automated with `set_artefacts()` will have the proper font. utils::browseURL(paste0(tempdir(),"/energian_tuonti_yhdysvalloista.png")) } # } # Revert to defaults: set_roboplot_options(reset = TRUE)