diff --git a/NAMESPACE b/NAMESPACE index 0504bb9..f82a684 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -21,10 +21,13 @@ export(search_bootstrap) export(search_fontawesome) export(theme_ggswim) export(theme_ggswim_dark) +importFrom(cli,cli) importFrom(cli,cli_abort) importFrom(cli,cli_alert_info) +importFrom(cli,cli_alert_success) importFrom(cli,cli_h2) importFrom(cli,cli_rule) +importFrom(cli,cli_ul) importFrom(cli,cli_vec) importFrom(cli,cli_warn) importFrom(dplyr,any_of) diff --git a/R/ggswim-package.R b/R/ggswim-package.R index 71886aa..a305ca7 100644 --- a/R/ggswim-package.R +++ b/R/ggswim-package.R @@ -6,7 +6,8 @@ #' Geom GeomSegment GeomText discrete_scale draw_key_text #' @importFrom dplyr case_when left_join arrange bind_rows select arrange any_of #' mutate pull if_else filter distinct -#' @importFrom cli cli_abort cli_vec cli_warn cli_rule cli_h2 cli_alert_info +#' @importFrom cli cli_abort cli_vec cli_warn cli_rule cli_h2 cli_alert_info cli +#' cli_alert_success cli_ul #' @importFrom rlang caller_arg caller_env as_label is_atomic get_expr .data #' is_empty := enquo quo_is_symbolic quo list2 try_fetch eval_tidy %||% #' @importFrom purrr map_lgl walk discard walk walk2 diff --git a/R/theme_ggswim.R b/R/theme_ggswim.R index 2aa65a4..98cc210 100644 --- a/R/theme_ggswim.R +++ b/R/theme_ggswim.R @@ -46,14 +46,14 @@ theme_ggswim <- function(base_size = 12, base_family = "") { plot.caption = element_text(size = 10, hjust = 1), # Axis text - axis.text = element_text(size = 10, face = "bold", colour = "#000000"), + axis.text = element_text(size = 10, colour = "#000000"), axis.text.x = element_text(margin = margin(t = 10)), axis.text.y = element_text(margin = margin(r = 10)), # Axis titles axis.title = element_text(size = 12, face = "bold", colour = "#000000"), - axis.title.x = element_text(size = 14, face = "bold", margin = margin(t = 10)), - axis.title.y = element_text(size = 14, face = "bold", margin = margin(r = 10)), + axis.title.x = element_text(size = 14, margin = margin(t = 10)), + axis.title.y = element_text(size = 14, margin = margin(r = 10)), # Axis tick marks axis.ticks = element_line(linewidth = 0.75, colour = "#000000"), @@ -66,7 +66,7 @@ theme_ggswim <- function(base_size = 12, base_family = "") { # Axis line axis.line = element_line( color = "#000000", - linewidth = 1 + linewidth = .5 ), # Remove grid lines @@ -92,14 +92,14 @@ theme_ggswim_dark <- function(base_size = 12, base_family = "") { plot.caption = element_text(size = 10, hjust = 1, colour = "#F0F0F0"), # Axis text - axis.text = element_text(size = 10, face = "bold", colour = "#F0F0F0"), + axis.text = element_text(size = 10, colour = "#F0F0F0"), axis.text.x = element_text(margin = margin(t = 10), colour = "#F0F0F0"), axis.text.y = element_text(margin = margin(r = 10), colour = "#F0F0F0"), # Axis titles axis.title = element_text(size = 12, face = "bold", colour = "#F0F0F0"), - axis.title.x = element_text(size = 14, face = "bold", margin = margin(t = 10), colour = "#F0F0F0"), - axis.title.y = element_text(size = 14, face = "bold", margin = margin(r = 10), colour = "#F0F0F0"), + axis.title.x = element_text(size = 14, margin = margin(t = 10), colour = "#F0F0F0"), + axis.title.y = element_text(size = 14, margin = margin(r = 10), colour = "#F0F0F0"), # Axis tick marks axis.ticks = element_line(linewidth = 0.75, colour = "#F0F0F0"), @@ -112,7 +112,7 @@ theme_ggswim_dark <- function(base_size = 12, base_family = "") { # Axis line axis.line = element_line( color = "#F0F0F0", # Orange axis line - linewidth = 1 + linewidth = .5 ), # Remove grid lines diff --git a/man/figures/README-unnamed-chunk-5-1.png b/man/figures/README-unnamed-chunk-5-1.png index 3e334c5..6d9abbb 100644 Binary files a/man/figures/README-unnamed-chunk-5-1.png and b/man/figures/README-unnamed-chunk-5-1.png differ diff --git a/vignettes/articles/gallery.Rmd b/vignettes/articles/gallery.Rmd index 9049cd8..68e88aa 100644 --- a/vignettes/articles/gallery.Rmd +++ b/vignettes/articles/gallery.Rmd @@ -37,7 +37,7 @@ 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 = sample(c("😊", "🎉", "✅", "💥", "✨"), 30, replace = TRUE) + glyph = NA ) |> mutate( glyph = dplyr::case_when( @@ -77,6 +77,102 @@ ggplot() + theme_ggswim() ``` +## Using FontAwesome Icons + +Next, we'll replace the emojis above with calls to `fontawesome()` icons: + +```{r} +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 + ) + ) + +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( + marker_data, + scale_marker_discrete(glyphs = glyph, limits = label, name = "Markers") + ) + + labs( + title = "Sample Swimmer Plot", + x = "Time", y = "Record ID" + ) + + theme_ggswim() +``` + +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](https://fontawesome.com/license/free). + +## Using Bootstrap Icons + +We can similarly use Bootstrap icons with `bootstrap()`: + +```{r} +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 + ) + ) + +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( + marker_data, + scale_marker_discrete(glyphs = glyph, limits = label, name = "Markers") + ) + + labs( + title = "Sample Swimmer Plot", + x = "Time", y = "Record ID" + ) + + theme_ggswim() +``` + +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](https://github.com/twbs/bootstrap/blob/main/LICENSE). + ## Themeing with ggswim Here we'll demonstrate some of the theme functions available with ggswim. These examples will use the same plot setup from the README, starting with the original output: diff --git a/vignettes/ggswim.Rmd b/vignettes/ggswim.Rmd index 8a02b87..bd628a3 100644 --- a/vignettes/ggswim.Rmd +++ b/vignettes/ggswim.Rmd @@ -186,3 +186,4 @@ p + Some additional considerations to keep in mind when working with ggswim: - **Rendering Emojis and Custom Shapes:** To ensure emojis and other custom shapes display correctly, users may need to [switch their graphics rendering device](https://support.posit.co/hc/en-us/articles/360017886674-Troubleshooting-RStudio-Rendering-Errors) to AGG. +- ggswim supports use of FontAwesome and Bootstrap icons for glyph definition in addition to shapes and emojis. Check out the Gallery for examples on how to add them to your plots!