😎 Give your xaringan slides some style
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

336 lines
16KB

  1. <!-- Generated by pkgdown: do not edit by hand -->
  2. <!DOCTYPE html>
  3. <html lang="en">
  4. <head>
  5. <meta charset="utf-8">
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  8. <title>The ggplot2 xaringanthemer base plot theme — theme_xaringan_base • xaringanthemer</title>
  9. <!-- jquery -->
  10. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
  11. <!-- Bootstrap -->
  12. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha256-bZLfwXAP04zRMK2BjiO8iu9pf4FbLqX6zitd+tIvLhE=" crossorigin="anonymous" />
  13. <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha256-nuL8/2cJ5NDSSwnKD8VqreErSWHtnEP9E7AySL+1ev4=" crossorigin="anonymous"></script>
  14. <!-- bootstrap-toc -->
  15. <link rel="stylesheet" href="../bootstrap-toc.css">
  16. <script src="../bootstrap-toc.js"></script>
  17. <!-- Font Awesome icons -->
  18. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous" />
  19. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin="anonymous" />
  20. <!-- clipboard.js -->
  21. <script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script>
  22. <!-- headroom.js -->
  23. <script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin="anonymous"></script>
  24. <script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script>
  25. <!-- pkgdown -->
  26. <link href="../pkgdown.css" rel="stylesheet">
  27. <script src="../pkgdown.js"></script>
  28. <link href="../extra.css" rel="stylesheet">
  29. <meta property="og:title" content="The ggplot2 xaringanthemer base plot theme — theme_xaringan_base" />
  30. <meta property="og:description" content="Lifecycle: Maturing
  31. Provides a base plot theme for ggplot2 to match the xaringan slide theme
  32. created by xaringanthemer. The theme is designed to create a general plot
  33. style from two colors, a background_color and a text_color (or foreground
  34. color). Also accepts an accent_color and an accent_secondary_color that are
  35. xaringanthemer is not required for the base theme. Use
  36. theme_xaringan() or theme_xaringan_inverse() in xaringan slides styled by
  37. xaringanthemer for a plot theme that matches the slide style." />
  38. <meta name="twitter:card" content="summary" />
  39. <meta name="twitter:creator" content="@grrrck" />
  40. <meta name="twitter:site" content="@grrrck" />
  41. <meta name="robots" content="noindex">
  42. <!-- mathjax -->
  43. <script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script>
  44. <script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script>
  45. <!--[if lt IE 9]>
  46. <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  47. <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  48. <![endif]-->
  49. </head>
  50. <body data-spy="scroll" data-target="#toc">
  51. <div class="container template-reference-topic">
  52. <header>
  53. <div class="navbar navbar-default navbar-fixed-top" role="navigation">
  54. <div class="container">
  55. <div class="navbar-header">
  56. <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
  57. <span class="sr-only">Toggle navigation</span>
  58. <span class="icon-bar"></span>
  59. <span class="icon-bar"></span>
  60. <span class="icon-bar"></span>
  61. </button>
  62. <span class="navbar-brand">
  63. <a class="navbar-link" href="../index.html">xaringanthemer</a>
  64. <span class="version label label-danger" data-toggle="tooltip" data-placement="bottom" title="In-development version">0.2.0.9100</span>
  65. </span>
  66. </div>
  67. <div id="navbar" class="navbar-collapse collapse">
  68. <ul class="nav navbar-nav">
  69. <li>
  70. <a href="../articles/xaringanthemer.html">Get started</a>
  71. </li>
  72. <li>
  73. <a href="../reference/index.html">Reference</a>
  74. </li>
  75. <li>
  76. <a href="../articles/themes.html">Themes</a>
  77. </li>
  78. <li>
  79. <a href="../articles/fonts.html">Fonts</a>
  80. </li>
  81. <li>
  82. <a href="../articles/template-variables.html">Template Variables</a>
  83. </li>
  84. </ul>
  85. <ul class="nav navbar-nav navbar-right">
  86. <li>
  87. <a href="../news/index.html">
  88. <span class="fa fa fa fa-newspaper-o fa-lg"></span>
  89. </a>
  90. </li>
  91. <li>
  92. <a href="https://github.com/gadenbuie/xaringanthemer">
  93. <span class="fa fa-github fa-lg"></span>
  94. </a>
  95. </li>
  96. <li>
  97. <a href="https://twitter.com/grrrck">
  98. <span class="fa fa-twitter fa-lg"></span>
  99. </a>
  100. </li>
  101. <li>
  102. <a href="https://www.garrickadenbuie.com">
  103. <span class="fa fa-home fa-lg"></span>
  104. </a>
  105. </li>
  106. </ul>
  107. </div><!--/.nav-collapse -->
  108. </div><!--/.container -->
  109. </div><!--/.navbar -->
  110. </header>
  111. <div class="row">
  112. <div class="col-md-9 contents">
  113. <div class="page-header">
  114. <h1>The ggplot2 xaringanthemer base plot theme</h1>
  115. <small class="dont-index">Source: <a href='https://github.com/gadenbuie/xaringanthemer/blob/master/R/ggplot2.R'><code>R/ggplot2.R</code></a></small>
  116. <div class="hidden name"><code>theme_xaringan_base.Rd</code></div>
  117. </div>
  118. <div class="ref-description">
  119. <p><strong>Lifecycle:</strong> <a href='https://www.tidyverse.org/lifecycle/#maturing'>Maturing</a></p>
  120. <p>Provides a base plot theme for <span class="pkg">ggplot2</span> to match the <span class="pkg">xaringan</span> slide theme
  121. created by <a href='xaringanthemer-package.html'>xaringanthemer</a>. The theme is designed to create a general plot
  122. style from two colors, a <code>background_color</code> and a <code>text_color</code> (or foreground
  123. color). Also accepts an <code>accent_color</code> and an <code>accent_secondary_color</code> that are
  124. <a href='xaringanthemer-package.html'>xaringanthemer</a> is not required for the base theme. Use
  125. <code><a href='theme_xaringan.html'>theme_xaringan()</a></code> or <code><a href='theme_xaringan_inverse.html'>theme_xaringan_inverse()</a></code> in xaringan slides styled by
  126. xaringanthemer for a plot theme that matches the slide style.</p>
  127. </div>
  128. <pre class="usage"><span class='fu'>theme_xaringan_base</span>(
  129. <span class='no'>text_color</span>,
  130. <span class='no'>background_color</span>,
  131. <span class='no'>...</span>,
  132. <span class='kw'>set_ggplot_defaults</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>,
  133. <span class='kw'>accent_color</span> <span class='kw'>=</span> <span class='kw'>NULL</span>,
  134. <span class='kw'>accent_secondary_color</span> <span class='kw'>=</span> <span class='kw'>NULL</span>,
  135. <span class='kw'>text_font</span> <span class='kw'>=</span> <span class='kw'>NULL</span>,
  136. <span class='kw'>text_font_use_google</span> <span class='kw'>=</span> <span class='kw'>NULL</span>,
  137. <span class='kw'>text_font_size</span> <span class='kw'>=</span> <span class='kw'>NULL</span>,
  138. <span class='kw'>title_font</span> <span class='kw'>=</span> <span class='kw'>NULL</span>,
  139. <span class='kw'>title_font_use_google</span> <span class='kw'>=</span> <span class='kw'>NULL</span>,
  140. <span class='kw'>title_font_size</span> <span class='kw'>=</span> <span class='kw'>NULL</span>,
  141. <span class='kw'>use_showtext</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>
  142. )</pre>
  143. <h2 class="hasAnchor" id="arguments"><a class="anchor" href="#arguments"></a>Arguments</h2>
  144. <table class="ref-arguments">
  145. <colgroup><col class="name" /><col class="desc" /></colgroup>
  146. <tr>
  147. <th>text_color</th>
  148. <td><p>Color for text and foreground</p></td>
  149. </tr>
  150. <tr>
  151. <th>background_color</th>
  152. <td><p>Color for background</p></td>
  153. </tr>
  154. <tr>
  155. <th>...</th>
  156. <td><p>Ignored</p></td>
  157. </tr>
  158. <tr>
  159. <th>set_ggplot_defaults</th>
  160. <td><p>Should defaults be set for <span class="pkg">ggplot2</span> <em>geoms</em>?
  161. Defaults to TRUE. To restore ggplot's defaults, or the previously set geom
  162. defaults, see <code><a href='theme_xaringan_set_defaults.html'>theme_xaringan_restore_defaults()</a></code>.</p></td>
  163. </tr>
  164. <tr>
  165. <th>accent_color</th>
  166. <td><p>Color for titles and accents, inherits from
  167. <code>header_color</code> or <code>text_color</code>. Used for the <code>title</code> base setting in
  168. <code><a href='https://ggplot2.tidyverse.org/reference/theme.html'>ggplot2::theme()</a></code>, and additionally for setting the <code>color</code> or <code>fill</code> of
  169. <span class="pkg">ggplot2</span> geom defaults.</p></td>
  170. </tr>
  171. <tr>
  172. <th>accent_secondary_color</th>
  173. <td><p>Color for secondary accents, inherits from
  174. <code>text_bold_color</code> or <code>accent_color</code>. Used only when setting <span class="pkg">ggplot2</span> geom
  175. defaults.</p></td>
  176. </tr>
  177. <tr>
  178. <th>text_font</th>
  179. <td><p>Font to use for text elements, passed to
  180. <code><a href='https://rdrr.io/pkg/sysfonts/man/font_add_google.html'>sysfonts::font_add_google()</a></code>, if available and <code>text_font_use_google</code> is
  181. <code>TRUE</code>. Inherits from <code>text_font_family</code>.</p></td>
  182. </tr>
  183. <tr>
  184. <th>text_font_use_google</th>
  185. <td><p>Is <code>text_font</code> available on <a href='https://fonts.google.com'>Google Fonts</a>?</p></td>
  186. </tr>
  187. <tr>
  188. <th>text_font_size</th>
  189. <td><p>Base text font size, inherits from <code>text_font_size</code>, or
  190. defaults to 11.</p></td>
  191. </tr>
  192. <tr>
  193. <th>title_font</th>
  194. <td><p>Font to use for title elements, passed to
  195. <code><a href='https://rdrr.io/pkg/sysfonts/man/font_add_google.html'>sysfonts::font_add_google()</a></code>, if available and <code>title_font_use_google</code> is
  196. <code>TRUE</code>. Inherits from <code>title_font_family</code>.</p></td>
  197. </tr>
  198. <tr>
  199. <th>title_font_use_google</th>
  200. <td><p>Is <code>title_font</code> available on <a href='https://fonts.google.com'>Google Fonts</a>?</p></td>
  201. </tr>
  202. <tr>
  203. <th>title_font_size</th>
  204. <td><p>Base text font size, inherits from <code>title_font_size</code>,
  205. or defaults to 14.</p></td>
  206. </tr>
  207. <tr>
  208. <th>use_showtext</th>
  209. <td><p>If <code>TRUE</code> (default) the <span class="pkg">showtext</span> package will be
  210. used to register Google fonts. Set to <code>FALSE</code> to disable this feature
  211. entirely, which may result in errors during plotting if the fonts used are
  212. not available locally.</p></td>
  213. </tr>
  214. </table>
  215. <h2 class="hasAnchor" id="value"><a class="anchor" href="#value"></a>Value</h2>
  216. <p>A ggplot2 theme</p>
  217. <h2 class="hasAnchor" id="see-also"><a class="anchor" href="#see-also"></a>See also</h2>
  218. <div class='dont-index'><p>Other xaringanthemer ggplot2 themes:
  219. <code><a href='theme_xaringan_inverse.html'>theme_xaringan_inverse</a>()</code>,
  220. <code><a href='theme_xaringan_set_defaults.html'>theme_xaringan_set_defaults</a>()</code>,
  221. <code><a href='theme_xaringan.html'>theme_xaringan</a>()</code></p></div>
  222. <h2 class="hasAnchor" id="examples"><a class="anchor" href="#examples"></a>Examples</h2>
  223. <pre class="examples"><div class='input'><span class='co'># Requires ggplot2</span>
  224. <span class='no'>has_ggplot2</span> <span class='kw'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/r/base/ns-load.html'>requireNamespace</a></span>(<span class='st'>"ggplot2"</span>, <span class='kw'>quietly</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>)
  225. <span class='kw'>if</span> (<span class='no'>has_ggplot2</span>) {
  226. <span class='fu'><a href='https://rdrr.io/r/base/library.html'>library</a></span>(<span class='no'>ggplot2</span>)
  227. <span class='no'>plot1</span> <span class='kw'>&lt;-</span> <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/ggplot.html'>ggplot</a></span>(<span class='no'>iris</span>) +
  228. <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/aes.html'>aes</a></span>(<span class='no'>Petal.Length</span>, <span class='no'>Petal.Width</span>) +
  229. <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/geom_point.html'>geom_point</a></span>() +
  230. <span class='fu'>theme_xaringan_base</span>(
  231. <span class='kw'>text_color</span> <span class='kw'>=</span> <span class='st'>"#602f6b"</span>, <span class='co'># imperial</span>
  232. <span class='kw'>background_color</span> <span class='kw'>=</span> <span class='st'>"#f8f8f8"</span>, <span class='co'># light gray</span>
  233. <span class='kw'>accent_color</span> <span class='kw'>=</span> <span class='st'>"#317873"</span>, <span class='co'># myrtle green</span>
  234. <span class='kw'>title_font</span> <span class='kw'>=</span> <span class='st'>"sans"</span>,
  235. <span class='kw'>text_font</span> <span class='kw'>=</span> <span class='st'>"serif"</span>,
  236. <span class='kw'>set_ggplot_defaults</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>
  237. ) +
  238. <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/labs.html'>labs</a></span>(
  239. <span class='kw'>title</span> <span class='kw'>=</span> <span class='st'>"Basic Iris Plot"</span>,
  240. <span class='kw'>subtitle</span> <span class='kw'>=</span> <span class='st'>"+ theme_xaringan_base()"</span>,
  241. <span class='kw'>caption</span> <span class='kw'>=</span> <span class='st'>"xaringanthemer"</span>
  242. )
  243. <span class='fu'><a href='https://rdrr.io/r/base/print.html'>print</a></span>(<span class='no'>plot1</span>)
  244. <span class='no'>plot2</span> <span class='kw'>&lt;-</span> <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/ggplot.html'>ggplot</a></span>(<span class='no'>iris</span>) +
  245. <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/aes.html'>aes</a></span>(<span class='no'>Sepal.Width</span>) +
  246. <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/geom_histogram.html'>geom_histogram</a></span>(<span class='kw'>binwidth</span> <span class='kw'>=</span> <span class='fl'>0.1</span>) +
  247. <span class='fu'>theme_xaringan_base</span>(
  248. <span class='kw'>text_color</span> <span class='kw'>=</span> <span class='st'>"#a8a9c8"</span>, <span class='co'># light purple</span>
  249. <span class='kw'>background_color</span> <span class='kw'>=</span> <span class='st'>"#303163"</span>, <span class='co'># deep slate purple</span>
  250. <span class='kw'>accent_color</span> <span class='kw'>=</span> <span class='st'>"#ffff99"</span>, <span class='co'># canary yellow</span>
  251. <span class='kw'>title_font</span> <span class='kw'>=</span> <span class='st'>"sans"</span>,
  252. <span class='kw'>text_font</span> <span class='kw'>=</span> <span class='st'>"serif"</span>,
  253. <span class='kw'>set_ggplot_defaults</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>
  254. ) +
  255. <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/labs.html'>labs</a></span>(
  256. <span class='kw'>title</span> <span class='kw'>=</span> <span class='st'>"Basic Iris Plot"</span>,
  257. <span class='kw'>subtitle</span> <span class='kw'>=</span> <span class='st'>"+ theme_xaringan_base()"</span>,
  258. <span class='kw'>caption</span> <span class='kw'>=</span> <span class='st'>"xaringanthemer"</span>
  259. )
  260. <span class='fu'><a href='https://rdrr.io/r/base/print.html'>print</a></span>(<span class='no'>plot2</span>)
  261. }</div><div class='img'><img src='theme_xaringan_base-1.png' alt='' width='700' height='433' /></div><div class='img'><img src='theme_xaringan_base-2.png' alt='' width='700' height='433' /></div></pre>
  262. </div>
  263. <div class="col-md-3 hidden-xs hidden-sm" id="pkgdown-sidebar">
  264. <nav id="toc" data-toggle="toc" class="sticky-top">
  265. <h2 data-toc-skip>Contents</h2>
  266. </nav>
  267. </div>
  268. </div>
  269. <footer>
  270. <div class="copyright">
  271. <p>Developed by <a href='https://www.garrickadenbuie.com'>Garrick Aden-Buie</a>.</p>
  272. </div>
  273. <div class="pkgdown">
  274. <p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.5.0.</p>
  275. </div>
  276. </footer>
  277. </div>
  278. </body>
  279. </html>