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

367 lines
17KB

  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>Themed ggplot2 Scales — scale_xaringan • 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="Themed ggplot2 Scales — scale_xaringan" />
  37. <meta property="og:description" content="Lifecycle: Maturing
  38. Color and fill single-color scales for discrete and continuous values,
  39. created using the primary accent color of the xaringanthemer styles. See
  40. vignette(&quot;ggplot2-themes&quot;) for more information and examples of
  41. xaringanthemer's ggplot2-related functions." />
  42. <meta property="og:image" content="https://pkg.garrickadenbuie.com/xaringanthemer/logo.png" />
  43. <meta name="twitter:card" content="summary" />
  44. <meta name="twitter:creator" content="@grrrck" />
  45. <meta name="twitter:site" content="@grrrck" />
  46. <!-- mathjax -->
  47. <script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script>
  48. <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>
  49. <!--[if lt IE 9]>
  50. <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  51. <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  52. <![endif]-->
  53. </head>
  54. <body data-spy="scroll" data-target="#toc">
  55. <div class="container template-reference-topic">
  56. <header>
  57. <div class="navbar navbar-default navbar-fixed-top" role="navigation">
  58. <div class="container">
  59. <div class="navbar-header">
  60. <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
  61. <span class="sr-only">Toggle navigation</span>
  62. <span class="icon-bar"></span>
  63. <span class="icon-bar"></span>
  64. <span class="icon-bar"></span>
  65. </button>
  66. <span class="navbar-brand">
  67. <a class="navbar-link" href="../index.html">xaringanthemer</a>
  68. <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.3.0.9000</span>
  69. </span>
  70. </div>
  71. <div id="navbar" class="navbar-collapse collapse">
  72. <ul class="nav navbar-nav">
  73. <li>
  74. <a href="../articles/xaringanthemer.html">Features</a>
  75. </li>
  76. <li>
  77. <a href="../reference/index.html">Reference</a>
  78. </li>
  79. <li>
  80. <a href="../articles/themes.html">Themes</a>
  81. </li>
  82. <li>
  83. <a href="../articles/ggplot2-themes.html">ggplot2 Themes</a>
  84. </li>
  85. <li class="dropdown">
  86. <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
  87. More
  88. <span class="caret"></span>
  89. </a>
  90. <ul class="dropdown-menu" role="menu">
  91. <li>
  92. <a href="../articles/fonts.html">Fonts</a>
  93. </li>
  94. <li>
  95. <a href="../articles/template-variables.html">Template Variables</a>
  96. </li>
  97. </ul>
  98. </li>
  99. </ul>
  100. <ul class="nav navbar-nav navbar-right">
  101. <li class="dropdown">
  102. <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
  103. <span class="fa fa fa fa-newspaper-o fa-lg"></span>
  104. <span class="caret"></span>
  105. </a>
  106. <ul class="dropdown-menu" role="menu">
  107. <li>
  108. <a href="https://garrickadenbuie.com/blog/xaringanthemer-v0-3-0/">xaringan 0.3.0</a>
  109. </li>
  110. <li class="divider"></li>
  111. <li>
  112. <a href="../news/index.html">Changelog</a>
  113. </li>
  114. </ul>
  115. </li>
  116. <li>
  117. <a href="https://github.com/gadenbuie/xaringanthemer">
  118. <span class="fa fa-github fa-lg"></span>
  119. </a>
  120. </li>
  121. <li>
  122. <a href="https://twitter.com/grrrck">
  123. <span class="fa fa-twitter fa-lg"></span>
  124. </a>
  125. </li>
  126. <li>
  127. <a href="https://www.garrickadenbuie.com">
  128. <span class="fa fa-home fa-lg"></span>
  129. </a>
  130. </li>
  131. </ul>
  132. </div><!--/.nav-collapse -->
  133. </div><!--/.container -->
  134. </div><!--/.navbar -->
  135. </header>
  136. <div class="row">
  137. <div class="col-md-9 contents">
  138. <div class="page-header">
  139. <h1>Themed ggplot2 Scales</h1>
  140. <small class="dont-index">Source: <a href='https://github.com/gadenbuie/xaringanthemer/blob/master/R/ggplot2.R'><code>R/ggplot2.R</code></a></small>
  141. <div class="hidden name"><code>scale_xaringan.Rd</code></div>
  142. </div>
  143. <div class="ref-description">
  144. <p><strong>Lifecycle:</strong> <a href='https://www.tidyverse.org/lifecycle/#maturing'>Maturing</a></p>
  145. <p>Color and fill single-color scales for discrete and continuous values,
  146. created using the primary accent color of the xaringanthemer styles. See
  147. <code><a href='../articles/ggplot2-themes.html'>vignette("ggplot2-themes")</a></code> for more information and examples of
  148. <span class="pkg">xaringanthemer</span>'s <span class="pkg">ggplot2</span>-related functions.</p>
  149. </div>
  150. <pre class="usage"><span class='fu'>scale_xaringan_discrete</span>(
  151. aes_type = <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span>(<span class='st'>"color"</span>, <span class='st'>"colour"</span>, <span class='st'>"fill"</span>),
  152. <span class='kw'>...</span>,
  153. color = <span class='kw'>NULL</span>,
  154. direction = <span class='fl'>1</span>,
  155. inverse = <span class='fl'>FALSE</span>
  156. )
  157. <span class='fu'>scale_xaringan_fill_discrete</span>(<span class='kw'>...</span>, color = <span class='kw'>NULL</span>, direction = <span class='fl'>1</span>, inverse = <span class='fl'>FALSE</span>)
  158. <span class='fu'>scale_xaringan_color_discrete</span>(
  159. <span class='kw'>...</span>,
  160. color = <span class='kw'>NULL</span>,
  161. direction = <span class='fl'>1</span>,
  162. inverse = <span class='fl'>FALSE</span>
  163. )
  164. <span class='fu'>scale_xaringan_colour_discrete</span>(
  165. <span class='kw'>...</span>,
  166. color = <span class='kw'>NULL</span>,
  167. direction = <span class='fl'>1</span>,
  168. inverse = <span class='fl'>FALSE</span>
  169. )
  170. <span class='fu'>scale_xaringan_continuous</span>(
  171. aes_type = <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span>(<span class='st'>"color"</span>, <span class='st'>"colour"</span>, <span class='st'>"fill"</span>),
  172. <span class='kw'>...</span>,
  173. color = <span class='kw'>NULL</span>,
  174. begin = <span class='fl'>0</span>,
  175. end = <span class='fl'>1</span>,
  176. inverse = <span class='fl'>FALSE</span>
  177. )
  178. <span class='fu'>scale_xaringan_fill_continuous</span>(
  179. <span class='kw'>...</span>,
  180. color = <span class='kw'>NULL</span>,
  181. begin = <span class='fl'>0</span>,
  182. end = <span class='fl'>1</span>,
  183. inverse = <span class='fl'>FALSE</span>
  184. )
  185. <span class='fu'>scale_xaringan_color_continuous</span>(
  186. <span class='kw'>...</span>,
  187. color = <span class='kw'>NULL</span>,
  188. begin = <span class='fl'>0</span>,
  189. end = <span class='fl'>1</span>,
  190. inverse = <span class='fl'>FALSE</span>
  191. )
  192. <span class='fu'>scale_xaringan_colour_continuous</span>(
  193. <span class='kw'>...</span>,
  194. color = <span class='kw'>NULL</span>,
  195. begin = <span class='fl'>0</span>,
  196. end = <span class='fl'>1</span>,
  197. inverse = <span class='fl'>FALSE</span>
  198. )</pre>
  199. <h2 class="hasAnchor" id="arguments"><a class="anchor" href="#arguments"></a>Arguments</h2>
  200. <table class="ref-arguments">
  201. <colgroup><col class="name" /><col class="desc" /></colgroup>
  202. <tr>
  203. <th>aes_type</th>
  204. <td><p>The type of aesthetic to which the scale is being applied.
  205. One of "color", "colour", or "fill".</p></td>
  206. </tr>
  207. <tr>
  208. <th>...</th>
  209. <td><p>Arguments passed on to either the <span class="pkg">colorspace</span> scale
  210. functions — one of <code><a href='http://colorspace.R-Forge.R-project.org//reference/scale_colour_discrete_sequential.html'>colorspace::scale_color_discrete_sequential()</a></code>,
  211. <code><a href='http://colorspace.R-Forge.R-project.org//reference/scale_colour_continuous_sequential.html'>colorspace::scale_color_continuous_sequential()</a></code>,
  212. <code><a href='http://colorspace.R-Forge.R-project.org//reference/scale_colour_discrete_sequential.html'>colorspace::scale_fill_discrete_sequential()</a></code>, or
  213. <code><a href='http://colorspace.R-Forge.R-project.org//reference/scale_colour_continuous_sequential.html'>colorspace::scale_fill_continuous_sequential()</a></code> — or to
  214. <a href='https://ggplot2.tidyverse.org/reference/continuous_scale.html'>ggplot2::continuous_scale</a> or <a href='https://ggplot2.tidyverse.org/reference/discrete_scale.html'>ggplot2::discrete_scale</a>.</p></td>
  215. </tr>
  216. <tr>
  217. <th>color</th>
  218. <td><p>A color value, in hex, to override the default color. Otherwise,
  219. the primary color of the resulting scale is chosen from the xaringanthemer
  220. slide styles.</p></td>
  221. </tr>
  222. <tr>
  223. <th>direction</th>
  224. <td><p>Direction of the discrete scale. Use values less than 0 to
  225. reverse the direction, e.g. <code>direction = -1</code>.</p></td>
  226. </tr>
  227. <tr>
  228. <th>inverse</th>
  229. <td><p>If <code>color</code> is not supplied and <code>inverse = TRUE</code>, a primary
  230. color is chosen to work well with the inverse slide styles, namely the
  231. value of <code>inverse_header_color</code></p></td>
  232. </tr>
  233. <tr>
  234. <th>begin</th>
  235. <td><p>Number in the range of <code>[0, 1]</code> indicating to which point in the color scale the smallest data value should be mapped.</p></td>
  236. </tr>
  237. <tr>
  238. <th>end</th>
  239. <td><p>Number in the range of <code>[0, 1]</code> indicating to which point in the color scale the largest data value should be mapped.</p></td>
  240. </tr>
  241. </table>
  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='kw'>has_ggplot2</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/r/base/ns-load.html'>requireNamespace</a></span>(<span class='st'>"ggplot2"</span>, quietly = <span class='fl'>TRUE</span>)
  245. <span class='co'>if</span> (<span class='kw'>has_ggplot2</span>) {
  246. <span class='fu'><a href='https://rdrr.io/r/base/library.html'>library</a></span>(<span class='kw'><a href='http://ggplot2.tidyverse.org'>ggplot2</a></span>)
  247. <span class='co'># Saving the theme to a temp file because this is an example</span>
  248. <span class='kw'>path_to_css_file</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/r/base/tempfile.html'>tempfile</a></span>(fileext = <span class='st'>".css"</span>)
  249. <span class='co'># Create the xaringan theme: dark blue background with teal green accents</span>
  250. <span class='fu'><a href='style_duo.html'>style_duo</a></span>(
  251. primary_color = <span class='st'>"#002b36"</span>,
  252. secondary_color = <span class='st'>"#31b09e"</span>,
  253. <span class='co'># Using basic fonts for this example, but the plot theme will</span>
  254. <span class='co'># automatically use your theme font if you use Google fonts</span>
  255. text_font_family = <span class='st'>"sans"</span>,
  256. header_font_family = <span class='st'>"serif"</span>,
  257. outfile = <span class='kw'>path_to_css_file</span>
  258. )
  259. <span class='co'># Here's some very basic example data</span>
  260. <span class='kw'>ex</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/r/base/data.frame.html'>data.frame</a></span>(
  261. name = <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span>(<span class='st'>"Couple"</span>, <span class='st'>"Few"</span>, <span class='st'>"Lots"</span>, <span class='st'>"Many"</span>),
  262. n = <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span>(<span class='fl'>2</span>, <span class='fl'>3</span>, <span class='fl'>5</span>, <span class='fl'>7</span>)
  263. )
  264. <span class='co'># Fill color scales demo</span>
  265. <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/ggplot.html'>ggplot</a></span>(<span class='kw'>ex</span>) <span class='op'>+</span>
  266. <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/aes.html'>aes</a></span>(<span class='kw'>name</span>, <span class='kw'>n</span>, fill = <span class='kw'>n</span>) <span class='op'>+</span>
  267. <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/geom_bar.html'>geom_col</a></span>() <span class='op'>+</span>
  268. <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/labs.html'>ggtitle</a></span>(<span class='st'>"Matching fill scales"</span>) <span class='op'>+</span>
  269. <span class='co'># themed to match the slides: dark blue background with teal text</span>
  270. <span class='fu'><a href='theme_xaringan.html'>theme_xaringan</a></span>() <span class='op'>+</span>
  271. <span class='co'># Fill color matches teal text</span>
  272. <span class='fu'>scale_xaringan_fill_continuous</span>()
  273. <span class='co'># Color scales demo</span>
  274. <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/ggplot.html'>ggplot</a></span>(<span class='kw'>ex</span>) <span class='op'>+</span>
  275. <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/aes.html'>aes</a></span>(<span class='kw'>name</span>, y = <span class='fl'>1</span>, color = <span class='kw'>name</span>) <span class='op'>+</span>
  276. <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/geom_point.html'>geom_point</a></span>(size = <span class='fl'>10</span>) <span class='op'>+</span>
  277. <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/labs.html'>ggtitle</a></span>(<span class='st'>"Matching color scales"</span>) <span class='op'>+</span>
  278. <span class='co'># themed to match the slides: dark blue background with teal text</span>
  279. <span class='fu'><a href='theme_xaringan.html'>theme_xaringan</a></span>() <span class='op'>+</span>
  280. <span class='co'># Fill color matches teal text</span>
  281. <span class='fu'>scale_xaringan_color_discrete</span>(direction = <span class='op'>-</span><span class='fl'>1</span>)
  282. }
  283. </div><div class='img'><img src='scale_xaringan-1.png' alt='' width='700' height='433' /></div><div class='input'>
  284. </div></pre>
  285. </div>
  286. <div class="col-md-3 hidden-xs hidden-sm" id="pkgdown-sidebar">
  287. <nav id="toc" data-toggle="toc" class="sticky-top">
  288. <h2 data-toc-skip>Contents</h2>
  289. </nav>
  290. </div>
  291. </div>
  292. <footer>
  293. <div class="copyright">
  294. <p>Developed by <a href='https://www.garrickadenbuie.com'>Garrick Aden-Buie</a>.</p>
  295. </div>
  296. <div class="pkgdown">
  297. <p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.6.1.</p>
  298. </div>
  299. </footer>
  300. </div>
  301. </body>
  302. </html>