|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447 |
- <!DOCTYPE html>
- <html lang="" xml:lang="">
- <head>
- <title>Introduction ggplot2</title>
- <meta charset="utf-8" />
- <meta name="author" content="Antoine Neuraz" />
- <script src="libs/header-attrs-2.5/header-attrs.js"></script>
- <link href="libs/remark-css-0.0.1/default.css" rel="stylesheet" />
- <link rel="stylesheet" href="css/my_style.css" type="text/css" />
- </head>
- <body>
- <textarea id="source">
-
-
-
-
- ## ggplot2 implémente la grammaire de la visualisation
-
- ## Les essentiels
-
- ### Data: Données source.
- --
-
- ### Geoms: Marques de la visualisation (points, lignes, ...)
- --
-
- ### Scales: Echelles de la visualisation (position, taille, couleur,...)
-
- ---
- ## ggplot2 implémente la grammaire de la visualisation
-
- ## Les bonus
-
- ### Stats: Opérations de modification des données sources (moyenne, ...)
-
- --
-
- ### Faceting: Découpe le dataset pour créer des sous-graphes
-
- --
- ### Coordinates: système de coordonnées de la visualisation
-
- ---
- class:
- # Architecture d'un graph avec ggplot2
-
-
- ```r
- ggplot(data = <DATA.FRAME>, # chargement des données
- aes(x=<VARIABLE1>, # définition des aesthetics (aes)
- y=<VARIABLE2>, # = échelles
- ...), # grand nombre d'aesthetics existent
- ) +
- geom_<*>()
- ```
-
- ---
- # Ressources
-
-
- ### Reference: [https://ggplot2.tidyverse.org/reference/]()
-
- ### aesthetics: [https://frama.link/tidyverse-aesthetics]()
-
-
-
- ---
-
- ## La base
-
- .small[
-
- ```r
- data("iris")
-
- ggplot(iris,
- aes(x=Sepal.Length,
- y=Sepal.Width))
- ```
-
- ![](lab01-ggplot-intro_files/figure-html/unnamed-chunk-2-1.png)<!-- -->
- ]
- ---
-
- ## Ajouter une geometrie
-
- .small[
-
- ```r
- ggplot(iris,
- aes(x=Sepal.Length,
- y=Sepal.Width)) + # le plus ajoute un layer
- * geom_point()
- ```
-
- ![](lab01-ggplot-intro_files/figure-html/unnamed-chunk-3-1.png)<!-- -->
- ]
-
- ---
- ## Ajouter une géométrie [2]
- .small[
-
- ```r
- ggplot(iris) +
- * geom_point(aes(x=Sepal.Length,
- * y=Sepal.Width))
- ```
-
- ![](lab01-ggplot-intro_files/figure-html/unnamed-chunk-4-1.png)<!-- -->
- ]
-
- ---
- # Ajouter un encodage (aesthetics)
- .small[
-
- ```r
- ggplot(iris,
- aes(x=Sepal.Length,
- y=Sepal.Width,
- * color = Species)) +
- geom_point()
- ```
-
- ![](lab01-ggplot-intro_files/figure-html/unnamed-chunk-5-1.png)<!-- -->
- ]
- ---
- ## Ajouter une 2ème géométrie
-
- .small[
-
- ```r
- ggplot(iris,
- aes(x=Sepal.Length,
- y=Sepal.Width,
- color = Species)) +
- geom_point() +
- * geom_smooth()
- ```
-
- ```
- ## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
- ```
-
- ![](lab01-ggplot-intro_files/figure-html/unnamed-chunk-6-1.png)<!-- -->
- ]
-
-
-
- ---
- ## Régler les options de la géométrie
-
- .small[
-
- ```r
- ggplot(iris,
- aes(x=Sepal.Length,
- y=Sepal.Width,
- color = Species)) +
- geom_point() +
- * geom_smooth(method='lm', se=FALSE)
- ```
-
- ```
- ## `geom_smooth()` using formula 'y ~ x'
- ```
-
- ![](lab01-ggplot-intro_files/figure-html/unnamed-chunk-7-1.png)<!-- -->
- ]
-
- ---
- ## Ajouter une facette
-
- .small[
-
- ```r
- ggplot(iris,
- aes(x=Sepal.Length,
- y=Sepal.Width,
- color = Species)) +
- geom_point() +
- geom_smooth(method='lm', se=FALSE) +
- * facet_grid(~Species)
- ```
-
- ```
- ## `geom_smooth()` using formula 'y ~ x'
- ```
-
- ![](lab01-ggplot-intro_files/figure-html/unnamed-chunk-8-1.png)<!-- -->
- ]
- ---
- ## Régler le thème
-
- .small[
-
- ```r
- ggplot(iris,
- aes(x=Sepal.Length,
- y=Sepal.Width,
- color = Species)) +
- geom_point() +
- geom_smooth(method='lm', se=FALSE) +
- facet_grid(~Species) +
- * theme_minimal()
- ```
-
- ```
- ## `geom_smooth()` using formula 'y ~ x'
- ```
-
- ![](lab01-ggplot-intro_files/figure-html/unnamed-chunk-9-1.png)<!-- -->
- ]
-
- ---
- ## Régler les titres et labels
-
- .small[
-
- ```r
- ggplot(iris,
- aes(x=Sepal.Length,
- y=Sepal.Width,
- color = Species)) +
- geom_point()+
- theme_minimal() +
- * labs(title = "Sépales des iris",
- * subtitle = "Longueur et largeur des sépales* en fonction de l'espèce",
- * x= "Longueur",
- * y = "Largeur",
- * caption = "* Chacune des pièces du calice de la fleur. / source: Iris dataset"
- * )
- ```
-
- ![](lab01-ggplot-intro_files/figure-html/unnamed-chunk-10-1.png)<!-- -->
- ]
-
- ---
- ## Ajuster la légende
-
- .small[
-
- ```r
- ggplot(iris,
- aes(x=Sepal.Length,
- y=Sepal.Width,
- color = Species)) +
- geom_point()+
- theme_minimal() +
- labs(title = "Sépales des iris",
- subtitle = "Longueur et largeur des sépales* en fonction de l'espèce",
- x= "Longueur",
- y = "Largeur",
- caption = "* Chacune des pièces du calice de la fleur. / source: Iris dataset"
- ) +
- * guides(color = guide_legend(title = "Espèce"))
- ```
-
- ![](lab01-ggplot-intro_files/figure-html/unnamed-chunk-11-1.png)<!-- -->
- ]
- ---
- ## Paufiner le thème
-
- .small[
-
- ```r
- ggplot(iris,
- aes(x=Sepal.Length,
- y=Sepal.Width,
- color = Species)) +
- geom_point()+
- theme_minimal() +
- labs(title = "Sépales des iris",
- subtitle = "Longueur et largeur des sépales* en fonction de l'espèce",
- x= "Longueur",
- y = "Largeur",
- caption = "* Chacune des pièces du calice de la fleur. / source: Iris dataset"
- ) +
- guides(color = guide_legend(title = "Espèce")) +
- * theme(panel.grid.minor = element_blank(),
- * legend.position = "bottom")
- ```
-
- ![](lab01-ggplot-intro_files/figure-html/unnamed-chunk-12-1.png)<!-- -->
- ]
- ---
- # A l'aide !!!
-
- ### site du tidyverse: [https://ggplot2.tidyverse.org]()
-
- ### R for datascience: [https://r4ds.had.co.nz/]()
-
- ### stackoverfow: [https://stackoverflow.com]()
-
- ### votre moteur de recherche préféré
-
- ---
- # TODO
-
- ### Ouvrir le dataset "mtcars"
-
- ### représenter le "Gross horsepower" en fonction du nombre de cylindres
-
- ### utiliser l'encodage multiple sur le nombre de cylindres
-
- ### ajouter l'information du nombre de carburateurs
-
- ### Paufiner le plot (axes, titres, thème)
-
- ---
- # TODO 2
-
- ### représenter la distribution du nombre de miles per gallon en histogramme
-
- ### représenter la distribution du nombre de miles per gallon en boxplot
-
- ### representer la distribution du nombre de miles per gallon en fonction du nombre de cylindres
-
- ### ajouter les points par dessus la distribution
-
- ### paufiner le plot (axes, titres, thème)
-
-
- </textarea>
- <style data-target="print-only">@media screen {.remark-slide-container{display:block;}.remark-slide-scaler{box-shadow:none;}}</style>
- <script src="https://remarkjs.com/downloads/remark-latest.min.js"></script>
- <script src="addons/macros.js"></script>
- <script>var slideshow = remark.create({
- "ratio": "4:3",
- "countIncrementalSlides": false,
- "self-contained": true,
- "highlightLines": true
- });
- if (window.HTMLWidgets) slideshow.on('afterShowSlide', function (slide) {
- window.dispatchEvent(new Event('resize'));
- });
- (function(d) {
- var s = d.createElement("style"), r = d.querySelector(".remark-slide-scaler");
- if (!r) return;
- s.type = "text/css"; s.innerHTML = "@page {size: " + r.style.width + " " + r.style.height +"; }";
- d.head.appendChild(s);
- })(document);
-
- (function(d) {
- var el = d.getElementsByClassName("remark-slides-area");
- if (!el) return;
- var slide, slides = slideshow.getSlides(), els = el[0].children;
- for (var i = 1; i < slides.length; i++) {
- slide = slides[i];
- if (slide.properties.continued === "true" || slide.properties.count === "false") {
- els[i - 1].className += ' has-continuation';
- }
- }
- var s = d.createElement("style");
- s.type = "text/css"; s.innerHTML = "@media print { .has-continuation { display: none; } }";
- d.head.appendChild(s);
- })(document);
- // delete the temporary CSS (for displaying all slides initially) when the user
- // starts to view slides
- (function() {
- var deleted = false;
- slideshow.on('beforeShowSlide', function(slide) {
- if (deleted) return;
- var sheets = document.styleSheets, node;
- for (var i = 0; i < sheets.length; i++) {
- node = sheets[i].ownerNode;
- if (node.dataset["target"] !== "print-only") continue;
- node.parentNode.removeChild(node);
- }
- deleted = true;
- });
- })();
- (function() {
- "use strict"
- // Replace <script> tags in slides area to make them executable
- var scripts = document.querySelectorAll(
- '.remark-slides-area .remark-slide-container script'
- );
- if (!scripts.length) return;
- for (var i = 0; i < scripts.length; i++) {
- var s = document.createElement('script');
- var code = document.createTextNode(scripts[i].textContent);
- s.appendChild(code);
- var scriptAttrs = scripts[i].attributes;
- for (var j = 0; j < scriptAttrs.length; j++) {
- s.setAttribute(scriptAttrs[j].name, scriptAttrs[j].value);
- }
- scripts[i].parentElement.replaceChild(s, scripts[i]);
- }
- })();
- (function() {
- var links = document.getElementsByTagName('a');
- for (var i = 0; i < links.length; i++) {
- if (/^(https?:)?\/\//.test(links[i].getAttribute('href'))) {
- links[i].target = '_blank';
- }
- }
- })();
- // adds .remark-code-has-line-highlighted class to <pre> parent elements
- // of code chunks containing highlighted lines with class .remark-code-line-highlighted
- (function(d) {
- const hlines = d.querySelectorAll('.remark-code-line-highlighted');
- const preParents = [];
- const findPreParent = function(line, p = 0) {
- if (p > 1) return null; // traverse up no further than grandparent
- const el = line.parentElement;
- return el.tagName === "PRE" ? el : findPreParent(el, ++p);
- };
-
- for (let line of hlines) {
- let pre = findPreParent(line);
- if (pre && !preParents.includes(pre)) preParents.push(pre);
- }
- preParents.forEach(p => p.classList.add("remark-code-has-line-highlighted"));
- })(document);</script>
-
- <script>
- slideshow._releaseMath = function(el) {
- var i, text, code, codes = el.getElementsByTagName('code');
- for (i = 0; i < codes.length;) {
- code = codes[i];
- if (code.parentNode.tagName !== 'PRE' && code.childElementCount === 0) {
- text = code.textContent;
- if (/^\\\((.|\s)+\\\)$/.test(text) || /^\\\[(.|\s)+\\\]$/.test(text) ||
- /^\$\$(.|\s)+\$\$$/.test(text) ||
- /^\\begin\{([^}]+)\}(.|\s)+\\end\{[^}]+\}$/.test(text)) {
- code.outerHTML = code.innerHTML; // remove <code></code>
- continue;
- }
- }
- i++;
- }
- };
- slideshow._releaseMath(document);
- </script>
- <!-- dynamically load mathjax for compatibility with self-contained -->
- <script>
- (function () {
- var script = document.createElement('script');
- script.type = 'text/javascript';
- script.src = 'https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-MML-AM_CHTML';
- if (location.protocol !== 'file:' && /^https?:/.test(script.src))
- script.src = script.src.replace(/^https?:/, '');
- document.getElementsByTagName('head')[0].appendChild(script);
- })();
- </script>
- </body>
- </html>
|