Skip to content

Instantly share code, notes, and snippets.

@baptiste
Last active May 6, 2023 02:07
Show Gist options
  • Save baptiste/f8ea90952c559bfb015390bc913af3fd to your computer and use it in GitHub Desktop.
Save baptiste/f8ea90952c559bfb015390bc913af3fd to your computer and use it in GitHub Desktop.
library(ggplot2)
library(tagger)
d <- data.frame(x=rep(1:10, 5*4*2), y=rnorm(10*5*4*2), f1=gl(4,10*5*2,labels=letters[1:4]), f2=gl(5,10*4*2,labels = LETTERS[1:5]), f3=gl(2,10*4*5))
p <- ggplot(d, aes(x,y)) +
facet_wrap(f1~f2+f3)
data <- ggplot_build(p)
str(data$layout$layout)
tag_pool <- glue::glue_data(data$layout$layout,"{f1}|{f2}, {f3}")
p2 <- p +
tagger::tag_facets(tag_pool = tag_pool, tag_suffix = '') +
theme(strip.background = element_blank(),
strip.text = element_blank(),
tagger.panel.tag.background = element_rect(fill='gold'))
egg::ggarrange(p +ggtitle("original"), p2+ggtitle("strips stripped"),ncol=2)
@baptiste
Copy link
Author

baptiste commented May 6, 2023

Screenshot 2023-05-06 at 14 07 03

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment