😎 Give your xaringan slides some style
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

137 lines
4.8KB

  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 = NULL
  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} 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. The default is \code{TRUE} when the \pkg{showtext}
  55. package is installed.}
  56. }
  57. \value{
  58. A ggplot2 theme
  59. }
  60. \description{
  61. \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#maturing}{\figure{lifecycle-maturing.svg}{options: alt='[Maturing]'}}}{\strong{[Maturing]}}
  62. Provides a base plot theme for \pkg{ggplot2} to match the \pkg{xaringan}
  63. slide theme created by \link{xaringanthemer}. The theme is designed to create a
  64. general plot style from two colors, a \code{background_color} and a \code{text_color}
  65. (or foreground color). Also accepts an \code{accent_color} and an
  66. \code{accent_secondary_color} that are \link{xaringanthemer} is not required for the
  67. base theme. Use \code{\link[=theme_xaringan]{theme_xaringan()}} or \code{\link[=theme_xaringan_inverse]{theme_xaringan_inverse()}} in xaringan
  68. slides styled by xaringanthemer for a plot theme that matches the slide
  69. style. See \code{vignette("ggplot2-themes")} for more information and examples.
  70. }
  71. \examples{
  72. # Requires ggplot2
  73. has_ggplot2 <- requireNamespace("ggplot2", quietly = TRUE)
  74. if (has_ggplot2) {
  75. library(ggplot2)
  76. plot1 <- ggplot(mpg) +
  77. aes(cty, hwy) +
  78. geom_point() +
  79. theme_xaringan_base(
  80. text_color = "#602f6b", # imperial
  81. background_color = "#f8f8f8", # light gray
  82. accent_color = "#317873", # myrtle green
  83. title_font = "sans",
  84. text_font = "serif",
  85. set_ggplot_defaults = TRUE
  86. ) +
  87. labs(
  88. title = "Fuel Efficiency of Various Cars",
  89. subtitle = "+ theme_xaringan_base()",
  90. caption = "xaringanthemer"
  91. )
  92. print(plot1)
  93. plot2 <- ggplot(mpg) +
  94. aes(hwy) +
  95. geom_histogram(binwidth = 2) +
  96. theme_xaringan_base(
  97. text_color = "#a8a9c8", # light purple
  98. background_color = "#303163", # deep slate purple
  99. accent_color = "#ffff99", # canary yellow
  100. title_font = "sans",
  101. text_font = "serif",
  102. set_ggplot_defaults = TRUE
  103. ) +
  104. labs(
  105. title = "Highway Fuel Efficiency",
  106. subtitle = "+ theme_xaringan_base()",
  107. caption = "xaringanthemer"
  108. )
  109. print(plot2)
  110. }
  111. }
  112. \seealso{
  113. Other xaringanthemer ggplot2 themes:
  114. \code{\link{theme_xaringan_inverse}()},
  115. \code{\link{theme_xaringan_set_defaults}()},
  116. \code{\link{theme_xaringan}()}
  117. }
  118. \concept{xaringanthemer ggplot2 themes}