Generate matching ggplot2 themes
gadenbuie opened this issue · comments
Let theme functions take a ggplot2
theme object, applies theme colors to key plot elements and sets default theme with theme_set()
. Also updates geom defaults.
Secondarily, the theme prep function can be exported as well so that users can separately construct the theme in case they don't want to set the global ggplot2 theme.
Work has started on this in ggplot2-theme branch.
Instead of the above implementation, the xaringanthemer CSS-writing functions now stash theme variables in a package environment. I've added theme_xaringan()
and theme_xaringan_inverse()
which provide ggplot2 themes matching the slide styles. These functions also by default set geom default colors and fills.
The idea is that to make the following work really well
```{r xaringan-themer, include=FALSE}
library(ggplot2)
library(xaringanthemer)
style_mono_light(
base_color = "#00589a",
text_font_google = google_font("Roboto")
)
theme_set(theme_xaringan())
```
Which will give plots like this by default
Rmd Source
# theme_xaringan()
```{r cars-themed, echo = FALSE, fig.width=6, fig.asp=0.6, out.width="100%"}
ggplot(mtcars) +
aes(wt, mpg) +
geom_smooth(method = "lm") +
geom_point() +
labs(title = "Something something cars",
subtitle = "A boring regression",
caption = "Source: {mtcars} of course",
x = "Weight of the car",
y = "Fuel efficiency (mpg)")
```