Support autoformatting of ggrepel functions
py9mrg opened this issue · comments
Hello,
I was wondering how much hassle it would be to include support for the ggrepel functions? Obviously we can manually do this with something like:
update_geom_defaults("text_repel",
list(family = "desired font", color = "desired color"))
and similar for label_repel
. But if theme_xaringan()
could do it for us that would be nice. I guess it shouldn't be too tricky to add a ggrepel = TRUE
argument into theme_xaringan()
, and whack in an if
statement - but if it could automatically pick up any geoms that are text
or label
and then set those accordingly, that might be quite a convenient solution (for the user). Assuming there's no extension packages around that have those in their geom names - which could make this more hassle than it's worth! Here's an MWE of what I mean:
---
title: "Example"
output: html_document
---
knitr::opts_chunk$set(echo = TRUE)
library(ggplot2)
library(tidyverse)
library(xaringanthemer)
style_mono_accent(
base_color = "#DC322F", # bright red
inverse_background_color = "#002B36", # dark dark blue
inverse_header_color = "#31b09e", # light aqua green
inverse_text_color = "#FFFFFF", # white
title_slide_background_color = "var(--base)",
text_font_google = google_font("Kelly Slab"),
header_font_google = google_font("Oleo Script")
)
data <- tibble(
label = LETTERS[1:5],
x = 1:5,
y = (1:5)^2
)
p_text <- data %>%
ggplot(aes(x = x, y = y, label = label)) +
geom_text() +
theme_xaringan()
p_text
library(ggrepel)
p_repel <- data %>%
ggplot(aes(x = x, y = y, label = label)) +
geom_text_repel() +
theme_xaringan()
p_repel
This seems reasonable. I think we could condition on testing if ggrepel
is installed before setting the defaults. Thanks for the reprex!