😎 Give your xaringan slides some style
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

135 lines
4.6KB

  1. % Generated by roxygen2: do not edit by hand
  2. % Please edit documentation in R/ggplot2.R
  3. \name{theme_xaringan_base}
  4. \alias{theme_xaringan_base}
  5. \title{The ggplot2 xaringanthemer base plot theme}
  6. \usage{
  7. theme_xaringan_base(
  8. text_color,
  9. background_color,
  10. ...,
  11. set_ggplot_defaults = TRUE,
  12. accent_color = NULL,
  13. accent_secondary_color = NULL,
  14. text_font = NULL,
  15. text_font_use_google = NULL,
  16. text_font_size = NULL,
  17. title_font = NULL,
  18. title_font_use_google = NULL,
  19. title_font_size = NULL,
  20. use_showtext = TRUE
  21. )
  22. }
  23. \arguments{
  24. \item{text_color}{Color for text and foreground}
  25. \item{background_color}{Color for background}
  26. \item{...}{Ignored}
  27. \item{set_ggplot_defaults}{Should defaults be set for \pkg{ggplot2} \emph{geoms}?
  28. Defaults to TRUE. To restore ggplot's defaults, or the previously set geom
  29. defaults, see \code{\link[=theme_xaringan_restore_defaults]{theme_xaringan_restore_defaults()}}.}
  30. \item{accent_color}{Color for titles and accents, inherits from
  31. \code{header_color} or \code{text_color}. Used for the \code{title} base setting in
  32. \code{\link[ggplot2:theme]{ggplot2::theme()}}, and additionally for setting the \code{color} or \code{fill} of
  33. \pkg{ggplot2} geom defaults.}
  34. \item{accent_secondary_color}{Color for secondary accents, inherits from
  35. \code{text_bold_color} or \code{accent_color}. Used only when setting \pkg{ggplot2} geom
  36. defaults.}
  37. \item{text_font}{Font to use for text elements, passed to
  38. \code{\link[sysfonts:font_add_google]{sysfonts::font_add_google()}}, if available and \code{text_font_use_google} is
  39. \code{TRUE}. Inherits from \code{text_font_family}. If manually specified, can be a
  40. \code{\link[=google_font]{google_font()}}.}
  41. \item{text_font_use_google}{Is \code{text_font} available on \href{https://fonts.google.com}{Google Fonts}?}
  42. \item{text_font_size}{Base text font size, inherits from \code{text_font_size}, or
  43. defaults to 11.}
  44. \item{title_font}{Font to use for title elements, passed to
  45. \code{\link[sysfonts:font_add_google]{sysfonts::font_add_google()}}, if available and \code{title_font_use_google} is
  46. \code{TRUE}. Inherits from \code{title_font_family}. If manually specified, can be a
  47. \code{\link[=google_font]{google_font()}}.}
  48. \item{title_font_use_google}{Is \code{title_font} available on \href{https://fonts.google.com}{Google Fonts}?}
  49. \item{title_font_size}{Base text font size, inherits from \code{title_font_size},
  50. or defaults to 14.}
  51. \item{use_showtext}{If \code{TRUE} (default) the \pkg{showtext} package will be
  52. used to register Google fonts. Set to \code{FALSE} to disable this feature
  53. entirely, which may result in errors during plotting if the fonts used are
  54. not available locally.}
  55. }
  56. \value{
  57. A ggplot2 theme
  58. }
  59. \description{
  60. \strong{Lifecycle:} \href{https://www.tidyverse.org/lifecycle/#maturing}{Maturing}
  61. Provides a base plot theme for \pkg{ggplot2} to match the \pkg{xaringan} slide theme
  62. created by \link{xaringanthemer}. The theme is designed to create a general plot
  63. style from two colors, a \code{background_color} and a \code{text_color} (or foreground
  64. color). Also accepts an \code{accent_color} and an \code{accent_secondary_color} that are
  65. \link{xaringanthemer} is not required for the base theme. Use
  66. \code{\link[=theme_xaringan]{theme_xaringan()}} or \code{\link[=theme_xaringan_inverse]{theme_xaringan_inverse()}} in xaringan slides styled by
  67. xaringanthemer for a plot theme that matches the slide style.
  68. }
  69. \examples{
  70. # Requires ggplot2
  71. has_ggplot2 <- requireNamespace("ggplot2", quietly = TRUE)
  72. if (has_ggplot2) {
  73. library(ggplot2)
  74. plot1 <- ggplot(iris) +
  75. aes(Petal.Length, Petal.Width) +
  76. geom_point() +
  77. theme_xaringan_base(
  78. text_color = "#602f6b", # imperial
  79. background_color = "#f8f8f8", # light gray
  80. accent_color = "#317873", # myrtle green
  81. title_font = "sans",
  82. text_font = "serif",
  83. set_ggplot_defaults = TRUE
  84. ) +
  85. labs(
  86. title = "Basic Iris Plot",
  87. subtitle = "+ theme_xaringan_base()",
  88. caption = "xaringanthemer"
  89. )
  90. print(plot1)
  91. plot2 <- ggplot(iris) +
  92. aes(Sepal.Width) +
  93. geom_histogram(binwidth = 0.1) +
  94. theme_xaringan_base(
  95. text_color = "#a8a9c8", # light purple
  96. background_color = "#303163", # deep slate purple
  97. accent_color = "#ffff99", # canary yellow
  98. title_font = "sans",
  99. text_font = "serif",
  100. set_ggplot_defaults = TRUE
  101. ) +
  102. labs(
  103. title = "Basic Iris Plot",
  104. subtitle = "+ theme_xaringan_base()",
  105. caption = "xaringanthemer"
  106. )
  107. print(plot2)
  108. }
  109. }
  110. \seealso{
  111. Other xaringanthemer ggplot2 themes:
  112. \code{\link{theme_xaringan_inverse}()},
  113. \code{\link{theme_xaringan_set_defaults}()},
  114. \code{\link{theme_xaringan}()}
  115. }
  116. \concept{xaringanthemer ggplot2 themes}