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.

lab02-perception-colors.html 9.9KB

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