Skip to contents

This is a small helper intended for ggplot layers that draw glyph-like icons via geom_text(). Scalar arguments are replicated to all shapes.

Usage

style_icon(
  icon,
  label = NULL,
  family = NULL,
  fontface = "plain",
  size = 6,
  halo_size = 1.1,
  when_close = 0.05
)

Arguments

icon

Character vector of icons (glyphs), one per shape.

label

Optional character vector of labels, one per shape. If length 1, it is replicated.

family

Optional character vector of font family names. If length 1, it is replicated. If NULL, a Font Awesome family is auto-detected via find_fa_family().

fontface

Character or numeric vector of font-face values passed to geom_text(). If length 1, it is replicated.

size

Numeric vector of ggplot2 text sizes (mm). If length 1, it is replicated.

halo_size

Numeric multiplier for the icon halo size. If length 1, it is replicated.

when_close

Numeric scalar. Stored as an attribute on the returned data frame and used by g6tr_dumbbell_plot() as the "closeness" threshold for deciding when endpoints should be vertically nudged to avoid overlap.

Value

A tibble with one row per icon and columns: icon, label, family, fontface, size, halo_size. The returned object also has an attribute when_close.

Examples

# Two icons with shared styling (scalar args are recycled)
style_icon(
  icon = c("A", "B"),
  label = c("First", "Second"),
  size = 7,
  halo_size = 1.2
)
#> ! Font Awesome not found on the system; falling back to the default font family "DejaVu Sans". If Font Awesome is installed, inspect `systemfonts::system_fonts()` to find the correct family name.
#> # A tibble: 2 × 6
#>   icon  label  family      fontface  size halo_size
#>   <chr> <chr>  <chr>       <chr>    <dbl>     <dbl>
#> 1 A     First  DejaVu Sans plain        7       1.2
#> 2 B     Second DejaVu Sans plain        7       1.2

# Per-icon sizes while keeping a shared family and per-icon font faces
style_icon(
  icon = c("A", "B"),
  family = "Helvetica",
  fontface = c("plain", "bold"),
  size = c(7, 8),
  halo_size = 1.15
)
#> ! Font family "Helvetica" not found; using default family "Nimbus Sans".
#> # A tibble: 2 × 6
#>   icon  label family      fontface  size halo_size
#>   <chr> <chr> <chr>       <chr>    <dbl>     <dbl>
#> 1 A     NA    Nimbus Sans plain        7      1.15
#> 2 B     NA    Nimbus Sans bold         8      1.15