Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

5 роки тому
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. <!DOCTYPE html>
  2. <html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <title>Chapitre 12 ggplot2 : techniques avancées | Visualisation de données : éléments théoriques et applications avec R</title>
  7. <meta name="description" content="Cours introductif à la visualisation de données avec R. Ce cours a pour but d introduire les concepts théoriques de base en visualisation ainsi que des exemples concrets." />
  8. <meta name="generator" content="bookdown 0.15 and GitBook 2.6.7" />
  9. <meta property="og:title" content="Chapitre 12 ggplot2 : techniques avancées | Visualisation de données : éléments théoriques et applications avec R" />
  10. <meta property="og:type" content="book" />
  11. <meta property="og:description" content="Cours introductif à la visualisation de données avec R. Ce cours a pour but d introduire les concepts théoriques de base en visualisation ainsi que des exemples concrets." />
  12. <meta name="twitter:card" content="summary" />
  13. <meta name="twitter:title" content="Chapitre 12 ggplot2 : techniques avancées | Visualisation de données : éléments théoriques et applications avec R" />
  14. <meta name="twitter:description" content="Cours introductif à la visualisation de données avec R. Ce cours a pour but d introduire les concepts théoriques de base en visualisation ainsi que des exemples concrets." />
  15. <meta name="author" content="Antoine Neuraz" />
  16. <meta name="date" content="2019-11-18" />
  17. <meta name="viewport" content="width=device-width, initial-scale=1" />
  18. <meta name="apple-mobile-web-app-capable" content="yes" />
  19. <meta name="apple-mobile-web-app-status-bar-style" content="black" />
  20. <link rel="prev" href="visualisation-de-texte-1.html"/>
  21. <link rel="next" href="references.html"/>
  22. <script src="libs/jquery-2.2.3/jquery.min.js"></script>
  23. <link href="libs/gitbook-2.6.7/css/style.css" rel="stylesheet" />
  24. <link href="libs/gitbook-2.6.7/css/plugin-table.css" rel="stylesheet" />
  25. <link href="libs/gitbook-2.6.7/css/plugin-bookdown.css" rel="stylesheet" />
  26. <link href="libs/gitbook-2.6.7/css/plugin-highlight.css" rel="stylesheet" />
  27. <link href="libs/gitbook-2.6.7/css/plugin-search.css" rel="stylesheet" />
  28. <link href="libs/gitbook-2.6.7/css/plugin-fontsettings.css" rel="stylesheet" />
  29. <link href="libs/gitbook-2.6.7/css/plugin-clipboard.css" rel="stylesheet" />
  30. <style type="text/css">
  31. a.sourceLine { display: inline-block; line-height: 1.25; }
  32. a.sourceLine { pointer-events: none; color: inherit; text-decoration: inherit; }
  33. a.sourceLine:empty { height: 1.2em; }
  34. .sourceCode { overflow: visible; }
  35. code.sourceCode { white-space: pre; position: relative; }
  36. pre.sourceCode { margin: 0; }
  37. @media screen {
  38. div.sourceCode { overflow: auto; }
  39. }
  40. @media print {
  41. code.sourceCode { white-space: pre-wrap; }
  42. a.sourceLine { text-indent: -1em; padding-left: 1em; }
  43. }
  44. pre.numberSource a.sourceLine
  45. { position: relative; left: -4em; }
  46. pre.numberSource a.sourceLine::before
  47. { content: attr(data-line-number);
  48. position: relative; left: -1em; text-align: right; vertical-align: baseline;
  49. border: none; pointer-events: all; display: inline-block;
  50. -webkit-touch-callout: none; -webkit-user-select: none;
  51. -khtml-user-select: none; -moz-user-select: none;
  52. -ms-user-select: none; user-select: none;
  53. padding: 0 4px; width: 4em;
  54. color: #aaaaaa;
  55. }
  56. pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
  57. div.sourceCode
  58. { }
  59. @media screen {
  60. a.sourceLine::before { text-decoration: underline; }
  61. }
  62. code span.al { color: #ff0000; font-weight: bold; } /* Alert */
  63. code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
  64. code span.at { color: #7d9029; } /* Attribute */
  65. code span.bn { color: #40a070; } /* BaseN */
  66. code span.bu { } /* BuiltIn */
  67. code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
  68. code span.ch { color: #4070a0; } /* Char */
  69. code span.cn { color: #880000; } /* Constant */
  70. code span.co { color: #60a0b0; font-style: italic; } /* Comment */
  71. code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
  72. code span.do { color: #ba2121; font-style: italic; } /* Documentation */
  73. code span.dt { color: #902000; } /* DataType */
  74. code span.dv { color: #40a070; } /* DecVal */
  75. code span.er { color: #ff0000; font-weight: bold; } /* Error */
  76. code span.ex { } /* Extension */
  77. code span.fl { color: #40a070; } /* Float */
  78. code span.fu { color: #06287e; } /* Function */
  79. code span.im { } /* Import */
  80. code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
  81. code span.kw { color: #007020; font-weight: bold; } /* Keyword */
  82. code span.op { color: #666666; } /* Operator */
  83. code span.ot { color: #007020; } /* Other */
  84. code span.pp { color: #bc7a00; } /* Preprocessor */
  85. code span.sc { color: #4070a0; } /* SpecialChar */
  86. code span.ss { color: #bb6688; } /* SpecialString */
  87. code span.st { color: #4070a0; } /* String */
  88. code span.va { color: #19177c; } /* Variable */
  89. code span.vs { color: #4070a0; } /* VerbatimString */
  90. code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
  91. </style>
  92. <link rel="stylesheet" href="style.css" type="text/css" />
  93. </head>
  94. <body>
  95. <div class="book without-animation with-summary font-size-2 font-family-1" data-basepath=".">
  96. <div class="book-summary">
  97. <nav role="navigation">
  98. <ul class="summary">
  99. <li><a href="./">Visualisation de données : éléments théoriques et applications avec R</a></li>
  100. <li class="divider"></li>
  101. <li class="chapter" data-level="" data-path="index.html"><a href="index.html"><i class="fa fa-check"></i>Prerequis</a><ul>
  102. <li class="chapter" data-level="" data-path="index.html"><a href="index.html#installer-r"><i class="fa fa-check"></i>Installer R</a></li>
  103. <li class="chapter" data-level="" data-path="index.html"><a href="index.html#installer-rstudio-facultatif"><i class="fa fa-check"></i>Installer RStudio (facultatif)</a></li>
  104. <li class="chapter" data-level="" data-path="index.html"><a href="index.html#installer-les-packages-nécessaires"><i class="fa fa-check"></i>Installer les packages nécessaires</a></li>
  105. </ul></li>
  106. <li class="chapter" data-level="1" data-path="intro.html"><a href="intro.html"><i class="fa fa-check"></i><b>1</b> Intro</a><ul>
  107. <li class="chapter" data-level="1.1" data-path="intro.html"><a href="intro.html#définition"><i class="fa fa-check"></i><b>1.1</b> Définition</a></li>
  108. <li class="chapter" data-level="1.2" data-path="intro.html"><a href="intro.html#todo"><i class="fa fa-check"></i><b>1.2</b> TODO</a></li>
  109. </ul></li>
  110. <li class="chapter" data-level="2" data-path="types-de-datasets-et-types-de-données.html"><a href="types-de-datasets-et-types-de-données.html"><i class="fa fa-check"></i><b>2</b> Types de datasets et types de données</a><ul>
  111. <li class="chapter" data-level="2.1" data-path="types-de-datasets-et-types-de-données.html"><a href="types-de-datasets-et-types-de-données.html#types-de-datasets"><i class="fa fa-check"></i><b>2.1</b> Types de datasets</a><ul>
  112. <li class="chapter" data-level="2.1.1" data-path="types-de-datasets-et-types-de-données.html"><a href="types-de-datasets-et-types-de-données.html#données-tabulaires"><i class="fa fa-check"></i><b>2.1.1</b> Données tabulaires</a></li>
  113. <li class="chapter" data-level="2.1.2" data-path="types-de-datasets-et-types-de-données.html"><a href="types-de-datasets-et-types-de-données.html#réseaux"><i class="fa fa-check"></i><b>2.1.2</b> Réseaux</a></li>
  114. <li class="chapter" data-level="2.1.3" data-path="types-de-datasets-et-types-de-données.html"><a href="types-de-datasets-et-types-de-données.html#todo-champs"><i class="fa fa-check"></i><b>2.1.3</b> TODO: Champs</a></li>
  115. <li class="chapter" data-level="2.1.4" data-path="types-de-datasets-et-types-de-données.html"><a href="types-de-datasets-et-types-de-données.html#todo-spacial"><i class="fa fa-check"></i><b>2.1.4</b> TODO: Spacial</a></li>
  116. </ul></li>
  117. <li class="chapter" data-level="2.2" data-path="types-de-datasets-et-types-de-données.html"><a href="types-de-datasets-et-types-de-données.html#types-de-données"><i class="fa fa-check"></i><b>2.2</b> Types de données</a><ul>
  118. <li class="chapter" data-level="2.2.1" data-path="types-de-datasets-et-types-de-données.html"><a href="types-de-datasets-et-types-de-données.html#todo-1"><i class="fa fa-check"></i><b>2.2.1</b> TODO</a></li>
  119. </ul></li>
  120. </ul></li>
  121. <li class="chapter" data-level="3" data-path="perception-système-visuel-marques-et-canaux-couleurs.html"><a href="perception-système-visuel-marques-et-canaux-couleurs.html"><i class="fa fa-check"></i><b>3</b> Perception : système visuel, marques et canaux, couleurs</a><ul>
  122. <li class="chapter" data-level="3.1" data-path="perception-système-visuel-marques-et-canaux-couleurs.html"><a href="perception-système-visuel-marques-et-canaux-couleurs.html#todo-2"><i class="fa fa-check"></i><b>3.1</b> TODO</a></li>
  123. <li class="chapter" data-level="3.2" data-path="perception-système-visuel-marques-et-canaux-couleurs.html"><a href="perception-système-visuel-marques-et-canaux-couleurs.html#types-de-marques"><i class="fa fa-check"></i><b>3.2</b> Types de marques</a></li>
  124. <li class="chapter" data-level="3.3" data-path="perception-système-visuel-marques-et-canaux-couleurs.html"><a href="perception-système-visuel-marques-et-canaux-couleurs.html#mappings-in-ggplot"><i class="fa fa-check"></i><b>3.3</b> Mappings in ggplot</a></li>
  125. <li class="chapter" data-level="3.4" data-path="perception-système-visuel-marques-et-canaux-couleurs.html"><a href="perception-système-visuel-marques-et-canaux-couleurs.html#scales-in-ggplot"><i class="fa fa-check"></i><b>3.4</b> scales in ggplot</a></li>
  126. </ul></li>
  127. <li class="chapter" data-level="4" data-path="abstraction-de-tâche.html"><a href="abstraction-de-tâche.html"><i class="fa fa-check"></i><b>4</b> Abstraction de tâche</a><ul>
  128. <li class="chapter" data-level="4.1" data-path="abstraction-de-tâche.html"><a href="abstraction-de-tâche.html#todo-3"><i class="fa fa-check"></i><b>4.1</b> TODO</a></li>
  129. </ul></li>
  130. <li class="chapter" data-level="5" data-path="principes-de-design.html"><a href="principes-de-design.html"><i class="fa fa-check"></i><b>5</b> Principes de design</a><ul>
  131. <li class="chapter" data-level="5.1" data-path="principes-de-design.html"><a href="principes-de-design.html#todo-4"><i class="fa fa-check"></i><b>5.1</b> TODO</a></li>
  132. </ul></li>
  133. <li class="chapter" data-level="6" data-path="visualisation-de-données-tabulaires.html"><a href="visualisation-de-données-tabulaires.html"><i class="fa fa-check"></i><b>6</b> Visualisation de données tabulaires</a><ul>
  134. <li class="chapter" data-level="6.1" data-path="visualisation-de-données-tabulaires.html"><a href="visualisation-de-données-tabulaires.html#todo-5"><i class="fa fa-check"></i><b>6.1</b> TODO</a></li>
  135. </ul></li>
  136. <li class="chapter" data-level="7" data-path="interaction.html"><a href="interaction.html"><i class="fa fa-check"></i><b>7</b> Interaction</a><ul>
  137. <li class="chapter" data-level="7.1" data-path="interaction.html"><a href="interaction.html#todo-6"><i class="fa fa-check"></i><b>7.1</b> TODO</a></li>
  138. </ul></li>
  139. <li class="chapter" data-level="8" data-path="visualisation-de-données-spatiales.html"><a href="visualisation-de-données-spatiales.html"><i class="fa fa-check"></i><b>8</b> Visualisation de données spatiales</a><ul>
  140. <li class="chapter" data-level="8.1" data-path="visualisation-de-données-spatiales.html"><a href="visualisation-de-données-spatiales.html#todo-7"><i class="fa fa-check"></i><b>8.1</b> TODO</a></li>
  141. </ul></li>
  142. <li class="chapter" data-level="9" data-path="visualisation-de-réseaux-et-graphes.html"><a href="visualisation-de-réseaux-et-graphes.html"><i class="fa fa-check"></i><b>9</b> Visualisation de réseaux et graphes</a></li>
  143. <li class="chapter" data-level="10" data-path="visualisation-de-texte.html"><a href="visualisation-de-texte.html"><i class="fa fa-check"></i><b>10</b> Visualisation de texte</a><ul>
  144. <li class="chapter" data-level="10.1" data-path="visualisation-de-texte.html"><a href="visualisation-de-texte.html#todo-8"><i class="fa fa-check"></i><b>10.1</b> TODO</a></li>
  145. </ul></li>
  146. <li class="chapter" data-level="11" data-path="visualisation-de-texte-1.html"><a href="visualisation-de-texte-1.html"><i class="fa fa-check"></i><b>11</b> Visualisation de texte</a><ul>
  147. <li class="chapter" data-level="11.1" data-path="visualisation-de-texte-1.html"><a href="visualisation-de-texte-1.html#todo-9"><i class="fa fa-check"></i><b>11.1</b> TODO</a></li>
  148. </ul></li>
  149. <li class="chapter" data-level="12" data-path="ggplot2-techniques-avancées.html"><a href="ggplot2-techniques-avancées.html"><i class="fa fa-check"></i><b>12</b> <code>ggplot2</code> : techniques avancées</a><ul>
  150. <li class="chapter" data-level="12.1" data-path="ggplot2-techniques-avancées.html"><a href="ggplot2-techniques-avancées.html#créer-son-propre-thème-ggplot2"><i class="fa fa-check"></i><b>12.1</b> Créer son propre thème <code>ggplot2</code></a><ul>
  151. <li class="chapter" data-level="12.1.1" data-path="ggplot2-techniques-avancées.html"><a href="ggplot2-techniques-avancées.html#un-thème-est-une-fonction"><i class="fa fa-check"></i><b>12.1.1</b> un thème est une fonction</a></li>
  152. <li class="chapter" data-level="12.1.2" data-path="ggplot2-techniques-avancées.html"><a href="ggplot2-techniques-avancées.html#modifier-un-thème-de-base-avec-replace"><i class="fa fa-check"></i><b>12.1.2</b> modifier un thème de base avec <code>%+replace%</code></a></li>
  153. <li class="chapter" data-level="12.1.3" data-path="ggplot2-techniques-avancées.html"><a href="ggplot2-techniques-avancées.html#définir-de-nouveaux-attributs"><i class="fa fa-check"></i><b>12.1.3</b> définir de nouveaux attributs</a></li>
  154. <li class="chapter" data-level="12.1.4" data-path="ggplot2-techniques-avancées.html"><a href="ggplot2-techniques-avancées.html#exemple"><i class="fa fa-check"></i><b>12.1.4</b> Exemple</a></li>
  155. </ul></li>
  156. <li class="chapter" data-level="12.2" data-path="ggplot2-techniques-avancées.html"><a href="ggplot2-techniques-avancées.html#utiliser-ggplot2-dans-des-fonctions"><i class="fa fa-check"></i><b>12.2</b> Utiliser <code>ggplot2</code> dans des fonctions</a></li>
  157. </ul></li>
  158. <li class="chapter" data-level="" data-path="references.html"><a href="references.html"><i class="fa fa-check"></i>References</a></li>
  159. <li class="divider"></li>
  160. <li><a href="https://github.com/rstudio/bookdown" target="blank">Published with bookdown</a></li>
  161. </ul>
  162. </nav>
  163. </div>
  164. <div class="book-body">
  165. <div class="body-inner">
  166. <div class="book-header" role="navigation">
  167. <h1>
  168. <i class="fa fa-circle-o-notch fa-spin"></i><a href="./">Visualisation de données : éléments théoriques et applications avec R</a>
  169. </h1>
  170. </div>
  171. <div class="page-wrapper" tabindex="-1" role="main">
  172. <div class="page-inner">
  173. <section class="normal" id="section-">
  174. <div id="ggplot2-techniques-avancées" class="section level1">
  175. <h1><span class="header-section-number">Chapitre 12</span> <code>ggplot2</code> : techniques avancées</h1>
  176. <div id="créer-son-propre-thème-ggplot2" class="section level2">
  177. <h2><span class="header-section-number">12.1</span> Créer son propre thème <code>ggplot2</code></h2>
  178. <p>Les thèmes de <code>ggplot2</code> permettent de contrôler l’apparence des plots. Il est possible de modifier un thème standard en utilisant la fonction <code>theme()</code>. Mais nous allons voir ici comment créer un thème personalisé.</p>
  179. <p>Il est bien entendu possible de créer un thème de toutes pièces. Pour cela, il faut définir un à un tous les éléments possibles du thème mais c’est très long et rébarbatif. Dans <code>ggplot2</code>, le seul thème défini de cette façon est le thème de base <code>theme_grey()</code> (voir le <a href="https://github.com/tidyverse/ggplot2/blob/master/R/theme-defaults.r">repo officiel</a>).
  180. Les autres thèmes héritent les attribut de ce premier thème et modifient uniquement éléments nécéssaires. Par exemple, <code>theme_bw()</code> est construit à partir de <code>theme_grey()</code> et <code>theme_minimal()</code> se base sur <code>theme_bw()</code>. C’est beaucoup plus pratique de définir les thèmes de cette façon.</p>
  181. <div id="un-thème-est-une-fonction" class="section level3">
  182. <h3><span class="header-section-number">12.1.1</span> un thème est une fonction</h3>
  183. <p>Un thème est une fonction R classique qui prend comme arguments 4 variables :
  184. - base_size : taille de base du texte (défaut = 11)
  185. - base_family : famille de polices de base (défaut = &quot;&quot;)
  186. - base_line_size : taille de base des éléments <code>line</code> (défaut = base_size / 22 )
  187. - base_rect_size : taille de base des éléments <code>rect</code> (défault = base_size / 22 )</p>
  188. <div class="sourceCode" id="cb6"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb6-1" data-line-number="1">my_theme &lt;-<span class="st"> </span><span class="cf">function</span>(<span class="dt">base_size =</span> <span class="dv">11</span>,</a>
  189. <a class="sourceLine" id="cb6-2" data-line-number="2"> <span class="dt">base_family =</span> <span class="st">&quot;&quot;</span>,</a>
  190. <a class="sourceLine" id="cb6-3" data-line-number="3"> <span class="dt">base_line_size =</span> base_size <span class="op">/</span><span class="st"> </span><span class="dv">22</span>,</a>
  191. <a class="sourceLine" id="cb6-4" data-line-number="4"> <span class="dt">base_rect_size =</span> base_size <span class="op">/</span><span class="st"> </span><span class="dv">22</span>) {}</a></code></pre></div>
  192. </div>
  193. <div id="modifier-un-thème-de-base-avec-replace" class="section level3">
  194. <h3><span class="header-section-number">12.1.2</span> modifier un thème de base avec <code>%+replace%</code></h3>
  195. <p>Ensuite, nous allons choisir un thème de base duquel notre thème personalisé va hériter les éléments par défaut. En effet, tous les éléments que nous ne spécifieront pas seront basés sur le thème de base. Par exemple, nous pouvons choisir <code>theme_minimal()</code>.</p>
  196. <p>Pour modifier les éléments du thème de base, il faut utiliser l’opérateur <code>%+replace%</code> suivi de la fonction <code>theme()</code>. C’est dans cette dernière que nous pourrons spécifier les différents éléments à modifier par rapport au thème de base.</p>
  197. <div class="sourceCode" id="cb7"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb7-1" data-line-number="1">my_theme &lt;-<span class="st"> </span><span class="cf">function</span>(<span class="dt">base_size =</span> <span class="dv">11</span>,</a>
  198. <a class="sourceLine" id="cb7-2" data-line-number="2"> <span class="dt">base_family =</span> <span class="st">&quot;&quot;</span>,</a>
  199. <a class="sourceLine" id="cb7-3" data-line-number="3"> <span class="dt">base_line_size =</span> base_size <span class="op">/</span><span class="st"> </span><span class="dv">22</span>,</a>
  200. <a class="sourceLine" id="cb7-4" data-line-number="4"> <span class="dt">base_rect_size =</span> base_size <span class="op">/</span><span class="st"> </span><span class="dv">22</span>) {</a>
  201. <a class="sourceLine" id="cb7-5" data-line-number="5"> </a>
  202. <a class="sourceLine" id="cb7-6" data-line-number="6"> <span class="kw">theme_minimal</span>(<span class="dt">base_size =</span> base_size, </a>
  203. <a class="sourceLine" id="cb7-7" data-line-number="7"> <span class="dt">base_family =</span> base_family,</a>
  204. <a class="sourceLine" id="cb7-8" data-line-number="8"> <span class="dt">base_line_size =</span> base_line_size,</a>
  205. <a class="sourceLine" id="cb7-9" data-line-number="9"> <span class="dt">base_rect_size =</span> base_rect_size) <span class="op">%+replace%</span></a>
  206. <a class="sourceLine" id="cb7-10" data-line-number="10"><span class="st"> </span><span class="kw">theme</span>(</a>
  207. <a class="sourceLine" id="cb7-11" data-line-number="11"> <span class="co"># éléments à modifier</span></a>
  208. <a class="sourceLine" id="cb7-12" data-line-number="12"> )</a>
  209. <a class="sourceLine" id="cb7-13" data-line-number="13">}</a></code></pre></div>
  210. </div>
  211. <div id="définir-de-nouveaux-attributs" class="section level3">
  212. <h3><span class="header-section-number">12.1.3</span> définir de nouveaux attributs</h3>
  213. <p>Nous pouvons a présent inserer dans la fonction thème les éléments à modifier. Notez qu’il ne faut pas utiliser de tailles absolues mais définir des tailles relatives avec la fonction <code>rel()</code>.</p>
  214. <div id="my_theme" class="section level4 unnumbered">
  215. <h4><code>my_theme()</code></h4>
  216. <p>Voici un exemple de thème personnalisé (très fortement inspiré du thème <code>theme_modern()</code> du package <code>see</code>) basé sur <code>theme_minimal()</code> :</p>
  217. <div class="sourceCode" id="cb8"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb8-1" data-line-number="1">my_theme &lt;-<span class="st"> </span><span class="cf">function</span>(<span class="dt">base_size =</span> <span class="dv">11</span>,</a>
  218. <a class="sourceLine" id="cb8-2" data-line-number="2"> <span class="dt">base_family =</span> <span class="st">&quot;&quot;</span>,</a>
  219. <a class="sourceLine" id="cb8-3" data-line-number="3"> <span class="dt">base_line_size =</span> base_size <span class="op">/</span><span class="st"> </span><span class="dv">22</span>,</a>
  220. <a class="sourceLine" id="cb8-4" data-line-number="4"> <span class="dt">base_rect_size =</span> base_size <span class="op">/</span><span class="st"> </span><span class="dv">22</span>) {</a>
  221. <a class="sourceLine" id="cb8-5" data-line-number="5"> </a>
  222. <a class="sourceLine" id="cb8-6" data-line-number="6"> half_line &lt;-<span class="st"> </span>base_size<span class="op">/</span><span class="dv">2</span></a>
  223. <a class="sourceLine" id="cb8-7" data-line-number="7"> </a>
  224. <a class="sourceLine" id="cb8-8" data-line-number="8"> <span class="kw">theme_minimal</span>(<span class="dt">base_size =</span> base_size, </a>
  225. <a class="sourceLine" id="cb8-9" data-line-number="9"> <span class="dt">base_family =</span> base_family,</a>
  226. <a class="sourceLine" id="cb8-10" data-line-number="10"> <span class="dt">base_line_size =</span> base_line_size,</a>
  227. <a class="sourceLine" id="cb8-11" data-line-number="11"> <span class="dt">base_rect_size =</span> base_rect_size) <span class="op">%+replace%</span></a>
  228. <a class="sourceLine" id="cb8-12" data-line-number="12"><span class="st"> </span><span class="kw">theme</span>(</a>
  229. <a class="sourceLine" id="cb8-13" data-line-number="13"> <span class="co">## Panel grid ##</span></a>
  230. <a class="sourceLine" id="cb8-14" data-line-number="14"> <span class="dt">panel.border =</span> <span class="kw">element_blank</span>(), </a>
  231. <a class="sourceLine" id="cb8-15" data-line-number="15"> <span class="dt">panel.grid.major =</span> <span class="kw">element_blank</span>(), </a>
  232. <a class="sourceLine" id="cb8-16" data-line-number="16"> <span class="dt">panel.grid.minor =</span> <span class="kw">element_blank</span>(), </a>
  233. <a class="sourceLine" id="cb8-17" data-line-number="17"> <span class="co">## Title ##</span></a>
  234. <a class="sourceLine" id="cb8-18" data-line-number="18"> <span class="dt">plot.title =</span> <span class="kw">element_text</span>(<span class="dt">size =</span> <span class="kw">rel</span>(<span class="fl">1.3</span>), </a>
  235. <a class="sourceLine" id="cb8-19" data-line-number="19"> <span class="dt">face =</span> <span class="st">&quot;plain&quot;</span>, <span class="dt">margin =</span> <span class="kw">margin</span>(<span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">20</span>, <span class="dv">0</span>)),</a>
  236. <a class="sourceLine" id="cb8-20" data-line-number="20"> <span class="co">## Axis ##</span></a>
  237. <a class="sourceLine" id="cb8-21" data-line-number="21"> <span class="dt">axis.line =</span> <span class="kw">element_line</span>(<span class="dt">colour =</span> <span class="st">&quot;black&quot;</span>, <span class="dt">size =</span> <span class="kw">rel</span>(<span class="fl">0.5</span>)), </a>
  238. <a class="sourceLine" id="cb8-22" data-line-number="22"> <span class="dt">axis.title.y =</span> <span class="kw">element_text</span>(<span class="dt">margin =</span> <span class="kw">margin</span>(<span class="dt">t =</span> <span class="dv">0</span>, <span class="dt">r =</span> <span class="kw">rel</span>(<span class="dv">20</span>), <span class="dt">b =</span> <span class="dv">0</span>, <span class="dt">l =</span> <span class="dv">0</span>),</a>
  239. <a class="sourceLine" id="cb8-23" data-line-number="23"> <span class="dt">angle =</span> <span class="dv">90</span>), </a>
  240. <a class="sourceLine" id="cb8-24" data-line-number="24"> <span class="dt">axis.title.x =</span> <span class="kw">element_text</span>(<span class="dt">margin =</span> <span class="kw">margin</span>(<span class="dt">t =</span> <span class="kw">rel</span>(<span class="dv">20</span>), <span class="dt">r =</span> <span class="dv">0</span>, <span class="dt">b =</span> <span class="dv">0</span>, <span class="dt">l =</span> <span class="dv">0</span>)), </a>
  241. <a class="sourceLine" id="cb8-25" data-line-number="25"> <span class="dt">axis.title =</span> <span class="kw">element_text</span>(<span class="dt">size =</span> <span class="kw">rel</span>(<span class="fl">1.2</span>), </a>
  242. <a class="sourceLine" id="cb8-26" data-line-number="26"> <span class="dt">face =</span> <span class="st">&quot;plain&quot;</span>), </a>
  243. <a class="sourceLine" id="cb8-27" data-line-number="27"> <span class="dt">axis.text =</span> <span class="kw">element_text</span>(<span class="dt">size =</span> <span class="kw">rel</span>(.<span class="dv">8</span>)), </a>
  244. <a class="sourceLine" id="cb8-28" data-line-number="28"> <span class="dt">axis.ticks =</span> <span class="kw">element_blank</span>(), </a>
  245. <a class="sourceLine" id="cb8-29" data-line-number="29"> <span class="co">## Legend ##</span></a>
  246. <a class="sourceLine" id="cb8-30" data-line-number="30"> <span class="dt">legend.key =</span> <span class="kw">element_blank</span>(), </a>
  247. <a class="sourceLine" id="cb8-31" data-line-number="31"> <span class="dt">legend.position =</span> <span class="st">&quot;bottom&quot;</span>,</a>
  248. <a class="sourceLine" id="cb8-32" data-line-number="32"> <span class="dt">legend.text =</span> <span class="kw">element_text</span>(<span class="dt">size =</span> <span class="kw">rel</span>(<span class="fl">1.1</span>)), </a>
  249. <a class="sourceLine" id="cb8-33" data-line-number="33"> <span class="dt">legend.title =</span> <span class="kw">element_text</span>(<span class="dt">size =</span> <span class="kw">rel</span>(<span class="fl">1.1</span>)), </a>
  250. <a class="sourceLine" id="cb8-34" data-line-number="34"> <span class="dt">legend.spacing.x =</span> <span class="kw">unit</span>(<span class="dv">2</span>, <span class="st">&quot;pt&quot;</span>), </a>
  251. <a class="sourceLine" id="cb8-35" data-line-number="35"> <span class="co">## Background ##</span></a>
  252. <a class="sourceLine" id="cb8-36" data-line-number="36"> <span class="dt">strip.background =</span> <span class="kw">element_blank</span>(), </a>
  253. <a class="sourceLine" id="cb8-37" data-line-number="37"> <span class="dt">plot.tag =</span> <span class="kw">element_text</span>(<span class="dt">size =</span> <span class="kw">rel</span>(<span class="fl">1.3</span>), <span class="dt">face =</span> <span class="st">&quot;bold&quot;</span>), </a>
  254. <a class="sourceLine" id="cb8-38" data-line-number="38"> <span class="dt">strip.text =</span> <span class="kw">element_text</span>(<span class="dt">face =</span> <span class="st">&quot;bold&quot;</span>)</a>
  255. <a class="sourceLine" id="cb8-39" data-line-number="39"> ) </a>
  256. <a class="sourceLine" id="cb8-40" data-line-number="40">}</a></code></pre></div>
  257. </div>
  258. <div id="my_theme_dark" class="section level4 unnumbered">
  259. <h4><code>my_theme_dark()</code></h4>
  260. <p>Et un thème sombre basé sur <code>my_theme()</code> et très fortement inspiré de <code>theme_blackboard()</code> du package <code>see</code> :</p>
  261. <div class="sourceCode" id="cb9"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb9-1" data-line-number="1">my_theme_dark &lt;-<span class="cf">function</span>(<span class="dt">base_size =</span> <span class="dv">11</span>,</a>
  262. <a class="sourceLine" id="cb9-2" data-line-number="2"> <span class="dt">base_family =</span> <span class="st">&quot;&quot;</span>,</a>
  263. <a class="sourceLine" id="cb9-3" data-line-number="3"> <span class="dt">base_line_size =</span> base_size <span class="op">/</span><span class="st"> </span><span class="dv">22</span>,</a>
  264. <a class="sourceLine" id="cb9-4" data-line-number="4"> <span class="dt">base_rect_size =</span> base_size <span class="op">/</span><span class="st"> </span><span class="dv">22</span>) {</a>
  265. <a class="sourceLine" id="cb9-5" data-line-number="5"> </a>
  266. <a class="sourceLine" id="cb9-6" data-line-number="6"> dark_color =<span class="st"> &quot;#0d0d0d&quot;</span></a>
  267. <a class="sourceLine" id="cb9-7" data-line-number="7"> light_color =<span class="st"> &quot;#E0E0E0&quot;</span></a>
  268. <a class="sourceLine" id="cb9-8" data-line-number="8"> </a>
  269. <a class="sourceLine" id="cb9-9" data-line-number="9"> <span class="kw">my_theme</span>(<span class="dt">base_size =</span> base_size, </a>
  270. <a class="sourceLine" id="cb9-10" data-line-number="10"> <span class="dt">base_family =</span> base_family,</a>
  271. <a class="sourceLine" id="cb9-11" data-line-number="11"> <span class="dt">base_line_size =</span> base_line_size,</a>
  272. <a class="sourceLine" id="cb9-12" data-line-number="12"> <span class="dt">base_rect_size =</span> base_rect_size) <span class="op">%+replace%</span></a>
  273. <a class="sourceLine" id="cb9-13" data-line-number="13"><span class="st"> </span></a>
  274. <a class="sourceLine" id="cb9-14" data-line-number="14"><span class="st"> </span><span class="kw">theme</span>(</a>
  275. <a class="sourceLine" id="cb9-15" data-line-number="15"> <span class="co">## Backgrounds ##</span></a>
  276. <a class="sourceLine" id="cb9-16" data-line-number="16"> <span class="dt">plot.background =</span> <span class="kw">element_rect</span>(<span class="dt">fill =</span> dark_color), </a>
  277. <a class="sourceLine" id="cb9-17" data-line-number="17"> <span class="dt">panel.background =</span> <span class="kw">element_rect</span>(<span class="dt">fill =</span> dark_color, <span class="dt">color=</span>dark_color), </a>
  278. <a class="sourceLine" id="cb9-18" data-line-number="18"> <span class="dt">legend.background =</span> <span class="kw">element_rect</span>(<span class="dt">fill =</span> dark_color, <span class="dt">color=</span>dark_color),</a>
  279. <a class="sourceLine" id="cb9-19" data-line-number="19"> <span class="co">## Lines ##</span></a>
  280. <a class="sourceLine" id="cb9-20" data-line-number="20"> <span class="dt">axis.line =</span> <span class="kw">element_line</span>(<span class="dt">color =</span> light_color),</a>
  281. <a class="sourceLine" id="cb9-21" data-line-number="21"> <span class="co">## Text ##</span></a>
  282. <a class="sourceLine" id="cb9-22" data-line-number="22"> <span class="dt">text =</span> <span class="kw">element_text</span>(<span class="dt">family =</span> base_family, <span class="dt">face =</span> <span class="st">&quot;plain&quot;</span>,</a>
  283. <a class="sourceLine" id="cb9-23" data-line-number="23"> <span class="dt">color =</span> light_color, <span class="dt">size =</span> base_size,</a>
  284. <a class="sourceLine" id="cb9-24" data-line-number="24"> <span class="dt">hjust =</span> <span class="fl">0.5</span>, <span class="dt">vjust =</span> <span class="fl">0.5</span>, <span class="dt">angle =</span> <span class="dv">0</span>, </a>
  285. <a class="sourceLine" id="cb9-25" data-line-number="25"> <span class="dt">lineheight =</span><span class="fl">0.9</span>, <span class="dt">margin =</span> <span class="kw">margin</span>(), </a>
  286. <a class="sourceLine" id="cb9-26" data-line-number="26"> <span class="dt">debug =</span> <span class="ot">FALSE</span>),</a>
  287. <a class="sourceLine" id="cb9-27" data-line-number="27"> <span class="dt">axis.text =</span> <span class="kw">element_text</span>(<span class="dt">color =</span> light_color)</a>
  288. <a class="sourceLine" id="cb9-28" data-line-number="28"> )</a>
  289. <a class="sourceLine" id="cb9-29" data-line-number="29">}</a></code></pre></div>
  290. </div>
  291. </div>
  292. <div id="exemple" class="section level3">
  293. <h3><span class="header-section-number">12.1.4</span> Exemple</h3>
  294. <p>Créons un plot d’exemple à partir d’un jeu de données synthétique</p>
  295. <div class="sourceCode" id="cb10"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb10-1" data-line-number="1">p &lt;-<span class="st"> </span><span class="kw">generate_uniform_dataset</span>(</a>
  296. <a class="sourceLine" id="cb10-2" data-line-number="2"> <span class="dt">dataset_size =</span> <span class="dv">100</span>,</a>
  297. <a class="sourceLine" id="cb10-3" data-line-number="3"> <span class="dt">min_x =</span> <span class="dv">0</span>, <span class="dt">max_x =</span> <span class="dv">1</span>,</a>
  298. <a class="sourceLine" id="cb10-4" data-line-number="4"> <span class="dt">outliers =</span> <span class="dv">2</span>, <span class="dt">seed =</span> <span class="dv">506</span></a>
  299. <a class="sourceLine" id="cb10-5" data-line-number="5">) <span class="op">%&gt;%</span></a>
  300. <a class="sourceLine" id="cb10-6" data-line-number="6"><span class="st"> </span><span class="kw">ggplot</span>(<span class="dt">data =</span> ., <span class="kw">aes</span>( <span class="dt">x =</span> x, <span class="dt">y =</span> y, <span class="dt">color =</span> group)) <span class="op">+</span></a>
  301. <a class="sourceLine" id="cb10-7" data-line-number="7"><span class="st"> </span><span class="kw">geom_point</span>(<span class="dt">size =</span> <span class="dv">3</span>) <span class="op">+</span></a>
  302. <a class="sourceLine" id="cb10-8" data-line-number="8"><span class="st"> </span><span class="kw">scale_color_material_d</span>() <span class="op">+</span></a>
  303. <a class="sourceLine" id="cb10-9" data-line-number="9"><span class="st"> </span><span class="kw">labs</span>(<span class="dt">x=</span><span class="st">&quot;legende axe x&quot;</span>, </a>
  304. <a class="sourceLine" id="cb10-10" data-line-number="10"> <span class="dt">y=</span><span class="st">&quot;legende axe y&quot;</span>)</a></code></pre></div>
  305. <div class="sourceCode" id="cb11"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb11-1" data-line-number="1">p </a></code></pre></div>
  306. <p><img src="dataviz_files/figure-html/unnamed-chunk-34-1.png" width="672" /></p>
  307. <div class="sourceCode" id="cb12"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb12-1" data-line-number="1">p <span class="op">+</span><span class="st"> </span><span class="kw">theme_minimal</span>() <span class="op">+</span><span class="st"> </span><span class="kw">labs</span>(<span class="dt">title=</span> <span class="st">&quot;theme_minimal&quot;</span>)</a></code></pre></div>
  308. <p><img src="dataviz_files/figure-html/unnamed-chunk-35-1.png" width="672" /></p>
  309. <div class="sourceCode" id="cb13"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb13-1" data-line-number="1">p <span class="op">+</span><span class="st"> </span><span class="kw">my_theme</span>() <span class="op">+</span><span class="st"> </span><span class="kw">labs</span>(<span class="dt">title=</span> <span class="st">&quot;my_theme&quot;</span>)</a></code></pre></div>
  310. <p><img src="dataviz_files/figure-html/unnamed-chunk-36-1.png" width="672" /></p>
  311. <div class="sourceCode" id="cb14"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb14-1" data-line-number="1">p <span class="op">+</span><span class="st"> </span><span class="kw">my_theme_dark</span>() <span class="op">+</span><span class="st"> </span><span class="kw">labs</span>(<span class="dt">title=</span> <span class="st">&quot;my_theme_dark&quot;</span>)</a></code></pre></div>
  312. <p><img src="dataviz_files/figure-html/unnamed-chunk-37-1.png" width="672" /></p>
  313. </div>
  314. </div>
  315. <div id="utiliser-ggplot2-dans-des-fonctions" class="section level2">
  316. <h2><span class="header-section-number">12.2</span> Utiliser <code>ggplot2</code> dans des fonctions</h2>
  317. <p>Pour utiliser les syntaxes décrites ici, vous aurez besoin de ggplot2 version &gt;= 3.2.</p>
  318. <p>Prenons l’exemple d’une fonction qui réalise un bar chart (diagramme en barres) pour une colonne données (par exemple <code>drv</code>) d’un dataset (par exemple <code>mpg</code>, fourni avec <code>ggplot2</code>)</p>
  319. <p>Le code pour réaliser ce plot en dehors d’une fonction peut ressembler à ceci :</p>
  320. <div class="sourceCode" id="cb15"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb15-1" data-line-number="1"><span class="kw">ggplot</span>(mpg) <span class="op">+</span><span class="st"> </span></a>
  321. <a class="sourceLine" id="cb15-2" data-line-number="2"><span class="st"> </span><span class="kw">geom_bar</span>(<span class="kw">aes</span>(<span class="dt">x =</span> drv))</a></code></pre></div>
  322. <p><img src="dataviz_files/figure-html/unnamed-chunk-38-1.png" width="672" /></p>
  323. <p>Dans une fonction, nous voudrions pouvoir utiliser un autre dataset et changer le nom de la variable d’intérêt.</p>
  324. <p>Modifier le nom du dataset ne pose pas de problème, et l’on peut utiliser une syntaxe classique :</p>
  325. <div class="sourceCode" id="cb16"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb16-1" data-line-number="1">my_bar &lt;-<span class="st"> </span><span class="cf">function</span>(df) {</a>
  326. <a class="sourceLine" id="cb16-2" data-line-number="2"> <span class="kw">ggplot</span>(df) <span class="op">+</span><span class="st"> </span></a>
  327. <a class="sourceLine" id="cb16-3" data-line-number="3"><span class="st"> </span><span class="kw">geom_bar</span>(<span class="kw">aes</span>(<span class="dt">x =</span> drv))</a>
  328. <a class="sourceLine" id="cb16-4" data-line-number="4">}</a>
  329. <a class="sourceLine" id="cb16-5" data-line-number="5"></a>
  330. <a class="sourceLine" id="cb16-6" data-line-number="6"><span class="kw">my_bar</span>(mpg)</a></code></pre></div>
  331. <p>Pour rendre modifiable le nom de la colonne, c’est à dire une variable qui est déclarée dans la fonction <code>aes()</code>, c’est moins immédiat. L’exemple suivant ne fonctionnera pas :</p>
  332. <div class="sourceCode" id="cb17"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb17-1" data-line-number="1">my_bar &lt;-<span class="st"> </span><span class="cf">function</span>(df, col) {</a>
  333. <a class="sourceLine" id="cb17-2" data-line-number="2"> <span class="kw">ggplot</span>(df) <span class="op">+</span><span class="st"> </span></a>
  334. <a class="sourceLine" id="cb17-3" data-line-number="3"><span class="st"> </span><span class="kw">geom_bar</span>(<span class="kw">aes</span>(<span class="dt">x =</span> col))</a>
  335. <a class="sourceLine" id="cb17-4" data-line-number="4">}</a>
  336. <a class="sourceLine" id="cb17-5" data-line-number="5"></a>
  337. <a class="sourceLine" id="cb17-6" data-line-number="6"><span class="kw">my_bar</span>(mpg, drv)</a></code></pre></div>
  338. <pre><code>Erreur : Aesthetics must be valid data columns. Problematic aesthetic(s): x = var. Did you mistype the name of a data column or forget to add stat()?</code></pre>
  339. <p>Pour résoudre ce problème, il faut utiliser une syntaxe particulière introduite dans la version 3.2 de ggplot2.
  340. Vous avez 2 solutions:
  341. - le nom de la colonne est passé en paramètre de la fonction comme un nom (c’est à dire sans &quot;&quot;, par exemple <code>drv</code>), vous devez encadrer le nom de la colonne par des doubles accolades : <code>{{ col }}</code></p>
  342. <div class="sourceCode" id="cb19"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb19-1" data-line-number="1">my_bar &lt;-<span class="st"> </span><span class="cf">function</span>(df, col) {</a>
  343. <a class="sourceLine" id="cb19-2" data-line-number="2"> <span class="kw">ggplot</span>(df) <span class="op">+</span><span class="st"> </span></a>
  344. <a class="sourceLine" id="cb19-3" data-line-number="3"><span class="st"> </span><span class="kw">geom_bar</span>(<span class="kw">aes</span>(<span class="dt">x =</span> {{ col }}))</a>
  345. <a class="sourceLine" id="cb19-4" data-line-number="4">}</a>
  346. <a class="sourceLine" id="cb19-5" data-line-number="5"></a>
  347. <a class="sourceLine" id="cb19-6" data-line-number="6"><span class="kw">my_bar</span>(mpg, drv)</a></code></pre></div>
  348. <ul>
  349. <li>le nom de la colonne est passé en paramètre de la fonction comme une chaine de caractère (par exemple: <code>&quot;drv&quot;</code>), vous devez utiliser la syntaxe suivante: <code>.data[[ col ]]</code></li>
  350. </ul>
  351. <div class="sourceCode" id="cb20"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb20-1" data-line-number="1">my_bar &lt;-<span class="st"> </span><span class="cf">function</span>(df, col) {</a>
  352. <a class="sourceLine" id="cb20-2" data-line-number="2"> <span class="kw">ggplot</span>(df) <span class="op">+</span><span class="st"> </span></a>
  353. <a class="sourceLine" id="cb20-3" data-line-number="3"><span class="st"> </span><span class="kw">geom_bar</span>(<span class="kw">aes</span>(<span class="dt">x =</span> .data[[ col ]] ))</a>
  354. <a class="sourceLine" id="cb20-4" data-line-number="4">}</a>
  355. <a class="sourceLine" id="cb20-5" data-line-number="5"></a>
  356. <a class="sourceLine" id="cb20-6" data-line-number="6"><span class="kw">my_bar</span>(mpg, <span class="st">&quot;drv&quot;</span>)</a></code></pre></div>
  357. </div>
  358. </div>
  359. </section>
  360. </div>
  361. </div>
  362. </div>
  363. <a href="visualisation-de-texte-1.html" class="navigation navigation-prev " aria-label="Previous page"><i class="fa fa-angle-left"></i></a>
  364. <a href="references.html" class="navigation navigation-next " aria-label="Next page"><i class="fa fa-angle-right"></i></a>
  365. </div>
  366. </div>
  367. <script src="libs/gitbook-2.6.7/js/app.min.js"></script>
  368. <script src="libs/gitbook-2.6.7/js/lunr.js"></script>
  369. <script src="libs/gitbook-2.6.7/js/clipboard.min.js"></script>
  370. <script src="libs/gitbook-2.6.7/js/plugin-search.js"></script>
  371. <script src="libs/gitbook-2.6.7/js/plugin-sharing.js"></script>
  372. <script src="libs/gitbook-2.6.7/js/plugin-fontsettings.js"></script>
  373. <script src="libs/gitbook-2.6.7/js/plugin-bookdown.js"></script>
  374. <script src="libs/gitbook-2.6.7/js/jquery.highlight.js"></script>
  375. <script src="libs/gitbook-2.6.7/js/plugin-clipboard.js"></script>
  376. <script>
  377. gitbook.require(["gitbook"], function(gitbook) {
  378. gitbook.start({
  379. "sharing": {
  380. "facebook": true,
  381. "twitter": true,
  382. "linkedin": false,
  383. "weibo": false,
  384. "instapaper": false,
  385. "vk": false,
  386. "all": ["facebook", "twitter", "linkedin", "weibo", "instapaper"]
  387. },
  388. "fontsettings": {
  389. "theme": "white",
  390. "family": "sans",
  391. "size": 2
  392. },
  393. "edit": {
  394. "link": null,
  395. "text": null
  396. },
  397. "history": {
  398. "link": null,
  399. "text": null
  400. },
  401. "download": ["dataviz.pdf", "dataviz.epub"],
  402. "toc": {
  403. "collapse": "subsection"
  404. }
  405. });
  406. });
  407. </script>
  408. </body>
  409. </html>