😎 Give your xaringan slides some style
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

133 lines
4.5KB

  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}.}
  40. \item{text_font_use_google}{Is \code{text_font} available on \href{https://fonts.google.com}{Google Fonts}?}
  41. \item{text_font_size}{Base text font size, inherits from \code{text_font_size}, or
  42. defaults to 11.}
  43. \item{title_font}{Font to use for title elements, passed to
  44. \code{\link[sysfonts:font_add_google]{sysfonts::font_add_google()}}, if available and \code{title_font_use_google} is
  45. \code{TRUE}. Inherits from \code{title_font_family}.}
  46. \item{title_font_use_google}{Is \code{title_font} available on \href{https://fonts.google.com}{Google Fonts}?}
  47. \item{title_font_size}{Base text font size, inherits from \code{title_font_size},
  48. or defaults to 14.}
  49. \item{use_showtext}{If \code{TRUE} (default) the \pkg{showtext} package will be
  50. used to register Google fonts. Set to \code{FALSE} to disable this feature
  51. entirely, which may result in errors during plotting if the fonts used are
  52. not available locally.}
  53. }
  54. \value{
  55. A ggplot2 theme
  56. }
  57. \description{
  58. \strong{Lifecycle:} \href{https://www.tidyverse.org/lifecycle/#maturing}{Maturing}
  59. Provides a base plot theme for \pkg{ggplot2} to match the \pkg{xaringan} slide theme
  60. created by \link{xaringanthemer}. The theme is designed to create a general plot
  61. style from two colors, a \code{background_color} and a \code{text_color} (or foreground
  62. color). Also accepts an \code{accent_color} and an \code{accent_secondary_color} that are
  63. \link{xaringanthemer} is not required for the base theme. Use
  64. \code{\link[=theme_xaringan]{theme_xaringan()}} or \code{\link[=theme_xaringan_inverse]{theme_xaringan_inverse()}} in xaringan slides styled by
  65. xaringanthemer for a plot theme that matches the slide style.
  66. }
  67. \examples{
  68. # Requires ggplot2
  69. has_ggplot2 <- requireNamespace("ggplot2", quietly = TRUE)
  70. if (has_ggplot2) {
  71. library(ggplot2)
  72. plot1 <- ggplot(iris) +
  73. aes(Petal.Length, Petal.Width) +
  74. geom_point() +
  75. theme_xaringan_base(
  76. text_color = "#602f6b", # imperial
  77. background_color = "#f8f8f8", # light gray
  78. accent_color = "#317873", # myrtle green
  79. title_font = "sans",
  80. text_font = "serif",
  81. set_ggplot_defaults = TRUE
  82. ) +
  83. labs(
  84. title = "Basic Iris Plot",
  85. subtitle = "+ theme_xaringan_base()",
  86. caption = "xaringanthemer"
  87. )
  88. print(plot1)
  89. plot2 <- ggplot(iris) +
  90. aes(Sepal.Width) +
  91. geom_histogram(binwidth = 0.1) +
  92. theme_xaringan_base(
  93. text_color = "#a8a9c8", # light purple
  94. background_color = "#303163", # deep slate purple
  95. accent_color = "#ffff99", # canary yellow
  96. title_font = "sans",
  97. text_font = "serif",
  98. set_ggplot_defaults = TRUE
  99. ) +
  100. labs(
  101. title = "Basic Iris Plot",
  102. subtitle = "+ theme_xaringan_base()",
  103. caption = "xaringanthemer"
  104. )
  105. print(plot2)
  106. }
  107. }
  108. \seealso{
  109. Other xaringanthemer ggplot2 themes:
  110. \code{\link{theme_xaringan_inverse}()},
  111. \code{\link{theme_xaringan_set_defaults}()},
  112. \code{\link{theme_xaringan}()}
  113. }
  114. \concept{xaringanthemer ggplot2 themes}