You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

402 lines
9.7KB

  1. <!DOCTYPE html>
  2. <html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
  3. <head>
  4. <title>LAB 2: Perception et couleurs</title>
  5. <meta charset="utf-8" />
  6. <meta name="author" content="Antoine Neuraz" />
  7. <link href="libs/remark-css-0.0.1/default.css" rel="stylesheet" />
  8. <link rel="stylesheet" href="css/my_style.css" type="text/css" />
  9. </head>
  10. <body>
  11. <textarea id="source">
  12. ---
  13. class: inverse, center, middle
  14. # Perception des différentes marques dans ggplot2
  15. ---
  16. ## TODO: échauffement
  17. #### Générer un dataset aléatoire avec la fonction vizoR::generate_dataset_uniform
  18. ```r
  19. size &lt;- list(100, 2)
  20. min_x &lt;- 0
  21. max_x &lt;- 1
  22. seed &lt;- 34
  23. ```
  24. ---
  25. ## TODO: perception
  26. #### 1. Réaliser des plots avec les échelles suivantes sur la variable group :
  27. - couleur
  28. - forme
  29. - angle
  30. - taille
  31. - luminosité
  32. - courbe
  33. - encapsulage
  34. - remplissage
  35. Certaines échelles sont très simples à mettre en place (e.g. couleur, forme) mais d'autres n'existent pas directement. Il faut trouver une alternative.
  36. #### 2. Comparer l'efficacité des différentes échelles pour distinguer les 2 groupes
  37. ---
  38. ## Couleur
  39. --
  40. .small[
  41. ```r
  42. p_color &lt;- ggplot( data = dt,
  43. aes(x = x, y = y, color = group)) +
  44. geom_point(size = 3, alpha = .6) +
  45. see::scale_color_material_d() +
  46. vizoR::theme_void_complete() +
  47. labs(subtitle= "Couleur")
  48. p_color
  49. ```
  50. ![](lab02-perception-colors_files/figure-html/unnamed-chunk-3-1.png)&lt;!-- --&gt;
  51. ]
  52. ---
  53. ## Angle
  54. --
  55. .small[
  56. ```r
  57. p_angle &lt;- dt %&gt;%
  58. mutate(angle = ifelse(group == "group1", 0, pi / 3)) %&gt;%
  59. ggplot(
  60. data = ., aes( x = x, y = y, angle = angle ) ) +
  61. geom_spoke(radius = 0.02,size = .8, alpha = .6 ) +
  62. theme_void_complete() +
  63. scale_color_material_d() +
  64. ggtitle("Angle")
  65. p_angle
  66. ```
  67. ![](lab02-perception-colors_files/figure-html/unnamed-chunk-4-1.png)&lt;!-- --&gt;
  68. ]
  69. ---
  70. ## Taille
  71. --
  72. .small[
  73. ```r
  74. p_size &lt;- dt %&gt;%
  75. mutate(size = ifelse(group == "group1", 2, 3)) %&gt;%
  76. ggplot( data = .,
  77. aes( x = x,y = y,size = size)) +
  78. geom_point(alpha = .6) +
  79. theme_void_complete() +
  80. scale_size(range = c(1, 3)) +
  81. ggtitle("Taille")
  82. p_size
  83. ```
  84. ![](lab02-perception-colors_files/figure-html/unnamed-chunk-5-1.png)&lt;!-- --&gt;
  85. ]
  86. ---
  87. ## Luminosité
  88. --
  89. .small[
  90. ```r
  91. p_grey &lt;- dt %&gt;%
  92. ggplot(
  93. data = .,aes(x = x,y = y,color = group)) +
  94. geom_point(size = 3, alpha = .6) +
  95. theme_void_complete() +
  96. #scale_color_grey() +
  97. scale_color_grey(start=.8, end=.2)+
  98. ggtitle("Luminosité")
  99. p_grey
  100. ```
  101. ![](lab02-perception-colors_files/figure-html/unnamed-chunk-6-1.png)&lt;!-- --&gt;
  102. ]
  103. ---
  104. ## Courbe
  105. --
  106. .small[
  107. ```r
  108. dt &lt;- dt %&gt;%
  109. mutate(curvature = ifelse(group == "group1", 0, 1))
  110. p_curve &lt;- dt %&gt;%
  111. ggplot(data = .,aes(x = x,y = y,xend = x, yend = y+max_x/50, curvature = curvature)) +
  112. #geom_curve()+
  113. geom_curve(data = subset(dt, group == 'group1'), curvature = 0, alpha = .7) +
  114. geom_curve(data = subset(dt, group == 'group2'), curvature = .7, alpha = .7) +
  115. scale_color_material_d() +
  116. theme_void_complete() +
  117. ggtitle("Courbe")
  118. p_curve
  119. ```
  120. ![](lab02-perception-colors_files/figure-html/unnamed-chunk-7-1.png)&lt;!-- --&gt;
  121. ]
  122. ---
  123. ## Encapsulage
  124. --
  125. .small[
  126. ```r
  127. p_box &lt;- dt %&gt;%
  128. ggplot(data = .,aes(x = x,xend = x+max_x/50,y = y,yend = y, group = group)) +
  129. geom_point(data = subset(dt, group=='group2'),aes(x = x+max_x/100), shape = 22, size = 13) +
  130. geom_segment() +
  131. scale_color_material_d() +
  132. theme_void_complete() +
  133. ggtitle("Encapsulage")
  134. p_box
  135. ```
  136. ![](lab02-perception-colors_files/figure-html/unnamed-chunk-8-1.png)&lt;!-- --&gt;
  137. ]
  138. ---
  139. ## Forme
  140. --
  141. .small[
  142. ```r
  143. p_shape &lt;- dt %&gt;%
  144. ggplot(data = .,aes(x = x,y = y,shape = group)) +
  145. geom_point(size = 3, alpha = .6) +
  146. theme_void_complete() +
  147. ggtitle("Forme")
  148. p_shape
  149. ```
  150. ![](lab02-perception-colors_files/figure-html/unnamed-chunk-9-1.png)&lt;!-- --&gt;
  151. ]
  152. ---
  153. ## Remplissage
  154. --
  155. .small[
  156. ```r
  157. p_fill &lt;- dt %&gt;%
  158. ggplot(data = ., aes( x = x,y = y,fill = group)) +
  159. geom_point(size = 3, shape = 21, alpha = .7) +
  160. scale_fill_manual(values = c('group2' = 'black', 'group1' = 'white')) +
  161. theme_void_complete() +
  162. ggtitle("Remplissage")
  163. p_fill
  164. ```
  165. ![](lab02-perception-colors_files/figure-html/unnamed-chunk-10-1.png)&lt;!-- --&gt;
  166. ]
  167. ---
  168. class: full, center, middle
  169. &lt;img src="lab02-perception-colors_files/figure-html/unnamed-chunk-11-1.png" width="2000px" /&gt;
  170. ---
  171. class: full
  172. ### Les couleurs dans ggplot2 `display.brewer.all()`
  173. ![:scale 80%](img/palettes.jpg)
  174. ---
  175. ## TODO: couleurs
  176. #### Charger le dataset diamonds et créer un sous-dataset aléatoire de 1000 lignes
  177. #### Plot carat en fonction du prix et de la couleur
  178. #### changer la palette par défaut vers une autre palette disponible
  179. ---
  180. ## TODO: couleurs 2
  181. #### Plot carat en fonction du prix avec carat en double encodage
  182. #### Aller sur [http://colorbrewer2.org]() et trouver une palette divergente
  183. #### Créer une palette custom basée sur cette palette et l'appliquer au plot précédent
  184. #### Caler la palette sur le carat moyen
  185. #### Annoter le plot avec une ligne désignant le carat moyen et un texte expliquant cette ligne
  186. ---
  187. ```r
  188. dsamp &lt;- diamonds[sample(nrow(diamonds), 1000), ]
  189. ggplot(dsamp, aes(carat, price)) +
  190. geom_point(aes(colour = color)) +
  191. scale_color_brewer(palette = "Set3") +
  192. facet_wrap(~color)
  193. ```
  194. ![](lab02-perception-colors_files/figure-html/unnamed-chunk-12-1.png)&lt;!-- --&gt;
  195. ```r
  196. ggplot(dsamp, aes(carat, price)) +
  197. geom_point(aes(colour = carat)) +
  198. scale_color_distiller(palette="RdYlBu")
  199. ```
  200. ![](lab02-perception-colors_files/figure-html/unnamed-chunk-13-1.png)&lt;!-- --&gt;
  201. ```r
  202. #showtext_auto()
  203. #font_add_google("Schoolbell", "bell")
  204. font_family = "sans"
  205. annotate_color = "grey50"
  206. midpoint = (max(dsamp$carat)-min(dsamp$carat))/2
  207. ggplot(dsamp, aes(carat, price)) +
  208. geom_vline(xintercept = midpoint, color = annotate_color) +
  209. geom_point(aes(colour = carat)) +
  210. scale_color_gradient2(low = "#d8b365",
  211. mid="#f5f5f5",
  212. high="#5ab4ac",
  213. midpoint = midpoint) +
  214. annotate("text",
  215. x=.78, y=15000, hjust=1, srt=40,
  216. label ="this is the midpoint",
  217. family=font_family,
  218. color=annotate_color) +
  219. annotate("curve",
  220. x = .8, xend=midpoint-.01, y=15000, yend = 14000,
  221. curvature = -.5,
  222. color=annotate_color ,
  223. arrow=arrow(length = unit(0.03, "npc") )) +
  224. theme_elegant() +
  225. theme(panel.grid.minor = element_blank(),
  226. panel.grid.major.x = element_blank(),
  227. legend.position = "none")
  228. ```
  229. ![](lab02-perception-colors_files/figure-html/unnamed-chunk-14-1.png)&lt;!-- --&gt;
  230. </textarea>
  231. <style data-target="print-only">@media screen {.remark-slide-container{display:block;}.remark-slide-scaler{box-shadow:none;}}</style>
  232. <script src="https://remarkjs.com/downloads/remark-latest.min.js"></script>
  233. <script src="addons/macros.js"></script>
  234. <script>var slideshow = remark.create({
  235. "ratio": "4:3",
  236. "countIncrementalSlides": false,
  237. "self-contained": true
  238. });
  239. if (window.HTMLWidgets) slideshow.on('afterShowSlide', function (slide) {
  240. window.dispatchEvent(new Event('resize'));
  241. });
  242. (function(d) {
  243. var s = d.createElement("style"), r = d.querySelector(".remark-slide-scaler");
  244. if (!r) return;
  245. s.type = "text/css"; s.innerHTML = "@page {size: " + r.style.width + " " + r.style.height +"; }";
  246. d.head.appendChild(s);
  247. })(document);
  248. (function(d) {
  249. var el = d.getElementsByClassName("remark-slides-area");
  250. if (!el) return;
  251. var slide, slides = slideshow.getSlides(), els = el[0].children;
  252. for (var i = 1; i < slides.length; i++) {
  253. slide = slides[i];
  254. if (slide.properties.continued === "true" || slide.properties.count === "false") {
  255. els[i - 1].className += ' has-continuation';
  256. }
  257. }
  258. var s = d.createElement("style");
  259. s.type = "text/css"; s.innerHTML = "@media print { .has-continuation { display: none; } }";
  260. d.head.appendChild(s);
  261. })(document);
  262. // delete the temporary CSS (for displaying all slides initially) when the user
  263. // starts to view slides
  264. (function() {
  265. var deleted = false;
  266. slideshow.on('beforeShowSlide', function(slide) {
  267. if (deleted) return;
  268. var sheets = document.styleSheets, node;
  269. for (var i = 0; i < sheets.length; i++) {
  270. node = sheets[i].ownerNode;
  271. if (node.dataset["target"] !== "print-only") continue;
  272. node.parentNode.removeChild(node);
  273. }
  274. deleted = true;
  275. });
  276. })();</script>
  277. <script>
  278. (function() {
  279. var links = document.getElementsByTagName('a');
  280. for (var i = 0; i < links.length; i++) {
  281. if (/^(https?:)?\/\//.test(links[i].getAttribute('href'))) {
  282. links[i].target = '_blank';
  283. }
  284. }
  285. })();
  286. </script>
  287. <script>
  288. slideshow._releaseMath = function(el) {
  289. var i, text, code, codes = el.getElementsByTagName('code');
  290. for (i = 0; i < codes.length;) {
  291. code = codes[i];
  292. if (code.parentNode.tagName !== 'PRE' && code.childElementCount === 0) {
  293. text = code.textContent;
  294. if (/^\\\((.|\s)+\\\)$/.test(text) || /^\\\[(.|\s)+\\\]$/.test(text) ||
  295. /^\$\$(.|\s)+\$\$$/.test(text) ||
  296. /^\\begin\{([^}]+)\}(.|\s)+\\end\{[^}]+\}$/.test(text)) {
  297. code.outerHTML = code.innerHTML; // remove <code></code>
  298. continue;
  299. }
  300. }
  301. i++;
  302. }
  303. };
  304. slideshow._releaseMath(document);
  305. </script>
  306. <!-- dynamically load mathjax for compatibility with self-contained -->
  307. <script>
  308. (function () {
  309. var script = document.createElement('script');
  310. script.type = 'text/javascript';
  311. script.src = 'https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-MML-AM_CHTML';
  312. if (location.protocol !== 'file:' && /^https?:/.test(script.src))
  313. script.src = script.src.replace(/^https?:/, '');
  314. document.getElementsByTagName('head')[0].appendChild(script);
  315. })();
  316. </script>
  317. </body>
  318. </html>