Skip to content

Commit

Permalink
Cleaning, updating vigenttes
Browse files Browse the repository at this point in the history
  • Loading branch information
rsh52 committed Nov 14, 2024
1 parent 1124896 commit 5247ad5
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 10 deletions.
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion R/ggswim-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions R/theme_ggswim.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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
Expand All @@ -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"),
Expand All @@ -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
Expand Down
Binary file modified man/figures/README-unnamed-chunk-5-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
98 changes: 97 additions & 1 deletion vignettes/articles/gallery.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 |>

Check warning on line 85 in vignettes/articles/gallery.Rmd

View workflow job for this annotation

GitHub Actions / lint

file=vignettes/articles/gallery.Rmd,line=85,col=30,[trailing_whitespace_linter] Trailing whitespace is superfluous.
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 |>

Check warning on line 135 in vignettes/articles/gallery.Rmd

View workflow job for this annotation

GitHub Actions / lint

file=vignettes/articles/gallery.Rmd,line=135,col=30,[trailing_whitespace_linter] Trailing whitespace is superfluous.
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:
Expand Down
1 change: 1 addition & 0 deletions vignettes/ggswim.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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!

0 comments on commit 5247ad5

Please sign in to comment.