Skip to content

Commit

Permalink
Reset default geom colors/fills after using theme_modern_rc
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewheiss committed May 29, 2023
1 parent 68b0ca1 commit 0817b89
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions slides/05-slides.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,24 @@ ggplot(mpg, aes(x = displ, y = hwy,

# And this!

```{r save-defaults, include=FALSE}
# There's a weird bug/feature in {hrbrthemes} where using theme_modern_rc()
# updates the default colors and fills for all geoms to be light blue
#
# - https://github.com/hrbrmstr/hrbrthemes/blob/master/R/modern.r
# - https://github.com/hrbrmstr/hrbrthemes/issues/58
#
# So we need to revert it all back to the defaults
default_point <- ggplot2:::check_subclass("point", "Geom")$default_aes
default_line <- ggplot2:::check_subclass("line", "Geom")$default_aes
default_area <- ggplot2:::check_subclass("area", "Geom")$default_aes
default_rect <- ggplot2:::check_subclass("rect", "Geom")$default_aes
default_density <- ggplot2:::check_subclass("density", "Geom")$default_aes
default_bar <- ggplot2:::check_subclass("bar", "Geom")$default_aes
default_col <- ggplot2:::check_subclass("col", "Geom")$default_aes
default_text <- ggplot2:::check_subclass("text", "Geom")$default_aes
```

.left-code[
```{r hrbrdark, tidy=FALSE, message=FALSE, fig.show="hide", fig.dim=c(4.8, 3.75), out.width="100%"}
library(hrbrthemes)
Expand All @@ -154,6 +172,17 @@ ggplot(mpg, aes(x = displ, y = hwy,
![](`r knitr::fig_chunk("hrbrdark", "png")`)
]

```{r fix-defaults, include=FALSE}
update_geom_defaults("point", default_point)
update_geom_defaults("line", default_line)
update_geom_defaults("area", default_area)
update_geom_defaults("rect", default_rect)
update_geom_defaults("density", default_density)
update_geom_defaults("bar", default_bar)
update_geom_defaults("col", default_col)
update_geom_defaults("text", default_text)
```

---

# Or this!
Expand Down

0 comments on commit 0817b89

Please sign in to comment.