😎 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.

358 lines
18KB

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