Skip to contents

This gallery collects small variations on ggswim plots. It assumes you already understand the lane and marker workflow from Getting Started, and focuses instead on glyph choices, icon fonts, and themes.

Emoji Markers with Simulated Data

In this example, we’ll set up simulated data for reproducibility by defining dataframes for our lanes and markers.

set.seed(123)
lane_data <- tibble(
  x = 0,
  xend = sample(5:20, 30, replace = TRUE),
  y = factor(rep(1:15, each = 2)),
  colour = sample(c("red", "blue", "green", "yellow", "purple"), 30, replace = TRUE)
)

set.seed(123)
marker_data <- tibble(
  x = sample(5:20, 30, replace = TRUE),
  y = factor(rep(1:15, each = 2)),
  label = sample(c("A", "B", "C", "D", "E"), 30, replace = TRUE),
  glyph = NA
) |>
  mutate(
    glyph = dplyr::case_when(
      label == "A" ~ "😊",
      label == "B" ~ "🎉",
      label == "C" ~ "✅",
      label == "D" ~ "💥",
      label == "E" ~ "✨",
      .default = NA
    )
  )

# The marker scale takes one style per category, not one style per event row.
emoji_styles <- marker_data |>
  distinct(label, glyph)

Now we can call those dataframes with their appropriate lane and marker layers:

ggplot() +
  geom_swim_lane(
    data = lane_data,
    aes(x = x, xend = xend, y = y, colour = colour),
    linewidth = 3
  ) +
  geom_swim_marker(
    data = marker_data,
    aes(x = x, y = y, marker = label),
    size = 8
  ) +
  scale_colour_brewer(name = "Lanes", palette = "Set1") +
  with(
    emoji_styles,
    scale_marker_discrete(glyphs = glyph, limits = label, name = "Markers")
  ) +
  labs(
    title = "Sample Swimmer Plot",
    x = "Time", y = "Record ID"
  ) +
  theme_ggswim()

A swimmer plot displaying use of emojis for event markers.

Using FontAwesome Icons

This example replaces the marker glyphs above with calls to fontawesome() icons after first loading fonts with load_fonts(). The first call to load_fonts() may require internet access because ggswim retrieves the font files from the GitHub repository. Subsequent calls reuse readable cached files and can work offline; missing or unreadable files are downloaded again.

The glyph value is the Unicode text returned by fontawesome(), and family must match the font collection that supplies that glyph. load_fonts() registers those font families before plotting; check the exported image or PDF as well as the on-screen preview because font availability can differ by graphics device.

# Load fonts from the ggswim GitHub repository
load_fonts(verbose = FALSE)

marker_data <- marker_data |>
  mutate(
    glyph = dplyr::case_when(
      label == "A" ~ fontawesome("fa-car"),
      label == "B" ~ fontawesome("fa-check"),
      label == "C" ~ fontawesome("fa-user"),
      label == "D" ~ fontawesome("fa-cat"),
      label == "E" ~ fontawesome("fa-dog"),
      .default = NA
    )
  )

fontawesome_styles <- marker_data |>
  distinct(label, glyph)

ggplot() +
  geom_swim_lane(
    data = lane_data,
    aes(x = x, xend = xend, y = y, colour = colour),
    linewidth = 3
  ) +
  geom_swim_marker(
    data = marker_data,
    aes(x = x, y = y, marker = label),
    size = 8, family = "FontAwesome-Solid"
  ) +
  scale_colour_brewer(name = "Lanes", palette = "Set1") +
  with(
    fontawesome_styles,
    scale_marker_discrete(glyphs = glyph, limits = label, name = "Markers")
  ) +
  labs(
    title = "Sample Swimmer Plot",
    x = "Time", y = "Record ID"
  ) +
  theme_ggswim()

A swimmer plot displaying use of FontAwesome icons for event markers.

Be sure to specify the appropriate family argument in geom_swim_marker(). For FontAwesome the following are available:

  • “FontAwesome-Solid”
  • “FontAwesome-Regular”
  • “FontAwesome-Brands”

You can use search_fontawesome() to check what icons are available to use.

ggswim supports FontAwesome free icons through the open source license.

Using Bootstrap Icons

We can similarly use Bootstrap icons with bootstrap():

marker_data <- marker_data |>
  mutate(
    glyph = dplyr::case_when(
      label == "A" ~ bootstrap("bs-car-front"),
      label == "B" ~ bootstrap("bs-folder-fill"),
      label == "C" ~ bootstrap("bs-clock-fill"),
      label == "D" ~ bootstrap("bs-check-circle-fill"),
      label == "E" ~ bootstrap("bs-chat-fill"),
      .default = NA
    )
  )

bootstrap_styles <- marker_data |>
  distinct(label, glyph)

ggplot() +
  geom_swim_lane(
    data = lane_data,
    aes(x = x, xend = xend, y = y, colour = colour),
    linewidth = 3
  ) +
  geom_swim_marker(
    data = marker_data,
    aes(x = x, y = y, marker = label),
    size = 8, family = "Bootstrap"
  ) +
  scale_colour_brewer(name = "Lanes", palette = "Set1") +
  with(
    bootstrap_styles,
    scale_marker_discrete(glyphs = glyph, limits = label, name = "Markers")
  ) +
  labs(
    title = "Sample Swimmer Plot",
    x = "Time", y = "Record ID"
  ) +
  theme_ggswim()

A swimmer plot displaying use of Bootstrap icons for event markers.

Be sure to specify the appropriate family argument in geom_swim_marker(). For Bootstrap you only need to specify “Bootstrap”.

You can use search_bootstrap() to check what icons are available to use.

ggswim supports Bootstrap free icons through the open source license.

Theming with ggswim

These examples show the theme functions available with ggswim. They use the same plot setup from the README, starting with the original output:

p

A swimmer plot displaying use of the default datasets in ggswim.

theme_ggswim()

A swimmer plot displaying use of the default datasets in ggswim and updated with theme_ggswim().

theme_ggswim_dark()

A swimmer plot displaying use of the default datasets in ggswim and updated with theme_ggswim_dark().