😎 Give your xaringan slides some style
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 satır
3.1KB

  1. <!-- Set link to theme-settings, template-variables, theme functions -->
  2. ```{r include=FALSE}
  3. IN_PKGDOWN <- identical(Sys.getenv("IN_PKGDOWN"), "true")
  4. ```
  5. First, add the `xaringan-themer.css` file to the YAML header of your xaringan slides.
  6. ```yaml
  7. output:
  8. xaringan::moon_reader:
  9. css: xaringan-themer.css
  10. ```
  11. Then, in a hidden chunk just after the knitr setup chunk, load **xaringanthemer** and try one of the [theme functions][theme-functions].
  12. ````markdown
  13. ```{r xaringan-themer, include=FALSE, warning=FALSE}`r ""`
  14. library(xaringanthemer)
  15. style_mono_accent(
  16. base_color = "#1c5253",
  17. header_font_google = google_font("Josefin Sans"),
  18. text_font_google = google_font("Montserrat", "300", "300i"),
  19. code_font_google = google_font("Fira Mono")
  20. )
  21. ```
  22. ````
  23. <img src="https://raw.githubusercontent.com/gadenbuie/xaringanthemer/assets/example_mono_accent_1c5253.png" alt="Example title and normal slides using a green xaringanthemer theme" data-external="1" />
  24. ### Matching ggplot Themes
  25. [showtext]: https://github.com/yixuan/showtext
  26. **xaringanthemer** even provides a [ggplot2] theme
  27. with `theme_xaringan()`
  28. that uses the colors and fonts from your slide theme.
  29. Built on the [showtext] package,
  30. and designed to work seamlessly with [Google Fonts](https://fonts.google.com).
  31. Color and fill scales are also provided
  32. for matching sequential color scales based on
  33. the primary color used in your slides.
  34. See `?scale_xaringan` for more details.
  35. More details and examples can be found in `vignette("ggplot2-themes")`.
  36. ```{r xaringanthemer-ggplot-setup, include=FALSE, eval=!IN_PKGDOWN}
  37. style_mono_accent(
  38. base_color = "#1c5253",
  39. header_font_google = google_font("Josefin Sans"),
  40. text_font_google = google_font("Montserrat", "300", "300i"),
  41. code_font_google = google_font("Fira Mono"),
  42. outfile = NULL
  43. )
  44. ```
  45. ```{r theme_xaringan_demo, echo=TRUE, warning=FALSE, fig.width=13, fig.height=5.5, eval=!IN_PKGDOWN, fig.showtext=TRUE}
  46. library(ggplot2)
  47. ggplot(diamonds) +
  48. aes(cut, fill = cut) +
  49. geom_bar(show.legend = FALSE) +
  50. labs(
  51. x = "Cut",
  52. y = "Count",
  53. title = "A Fancy diamonds Plot"
  54. ) +
  55. theme_xaringan(background_color = "#FFFFFF") +
  56. scale_xaringan_fill_discrete()
  57. ```
  58. ```{r link-to-plot-image, echo=FALSE, eval=IN_PKGDOWN, results='asis'}
  59. cat("![](../reference/figures/index-theme_xaringan_demo-1.png)")
  60. ```
  61. ### Tab Completion
  62. **xaringanthemer** is <kbd>Tab</kbd> friendly -- [use autocomplete to explore][theme-settings] the [template variables][template-variables] that you can adjust in each of the themes!
  63. <img src="https://raw.githubusercontent.com/gadenbuie/xaringanthemer/assets/example-rstudio-completion.gif" alt="Demonstration of argument auto-completion with RStudio" data-external="1" />
  64. ### R Markdown Template in RStudio
  65. You can also skip the above and just create a *Ninja Themed Presentation* from the New R Markdown Document menu in RStudio.
  66. <center>
  67. <img src="https://raw.githubusercontent.com/gadenbuie/xaringanthemer/assets/rmarkdown-template-screenshot.png" alt="The 'New R Markdown Document' menu in RStudio" data-external="1" />
  68. </center>