class: center, middle, inverse, title-slide .title[ # ggplot Part I ] .subtitle[ ## Workshop on Data Visualization in R ] .author[ ###
Lokesh Mano
• 29-Apr-2022 ] .institute[ ### NBIS, SciLifeLab ] --- exclude: true count: false <link href="https://fonts.googleapis.com/css?family=Roboto|Source+Sans+Pro:300,400,600|Ubuntu+Mono&subset=latin-ext" rel="stylesheet"> <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous"> <!-- ------------ Only edit title, subtitle & author above this ------------ --> --- name: content class: spaced ## Contents * [Grammer of Graphics](#gog) * [Building a graph](#build) * [Build-Demo](#build-demo) * [Geoms](#geoms) * [Aesthetics](#aesth) * [Multiple Geoms](#mul-geom) --- name: gog ## Grammar of Graphics .pull-left-30[ <img src="assets/images/gog.png" alt="drawing" width="300"/> ] -- .pull-right-70[ * **Data:** Input data * **Geom:** A geometry representing data. Points, Lines etc * **Aesthetics:** Visual characteristics of the geometry. Size, Color, Shape etc * **Scale:** How visual characteristics are converted to display values * **Statistics:** Statistical transformations. Counts, Means etc * **Coordinates:** Numeric system to determine position of geometry. Cartesian, Polar etc * **Facets:** Split data into subsets ] --- name: build class: spaced ## Building a graph <img src="assets/images/gg-syntax.png" alt="drawing", width ="600"/> --- name: build-demo ## Build-Demo .pull-left-50[ ```r ggplot(iris) ``` ] .pull-right-50[ <img src="slide_gg1_files/figure-html/unnamed-chunk-4-1.svg" style="display: block; margin: auto auto auto 0;" /> ] --- name: build-demo2 ## Build-Demo .pull-left-50[ ```r ggplot(iris,aes(x=Sepal.Length, y=Sepal.Width)) ``` ] .pull-right-50[ <img src="slide_gg1_files/figure-html/unnamed-chunk-6-1.svg" style="display: block; margin: auto auto auto 0;" /> ] --- name: build-demo3 ## Build-Demo .pull-left-50[ ```r ggplot(iris,aes(x=Sepal.Length, y=Sepal.Width))+ geom_point() ``` ] .pull-right-50[ <img src="slide_gg1_files/figure-html/unnamed-chunk-8-1.svg" style="display: block; margin: auto auto auto 0;" /> ] --- name: build-demo4 ## Build-Demo .pull-left-50[ ```r ggplot(iris,aes(x=Sepal.Length, y=Sepal.Width, colour=Species))+ geom_point() ``` ] .pull-right-50[ <img src="slide_gg1_files/figure-html/unnamed-chunk-10-1.svg" style="display: block; margin: auto auto auto 0;" /> ] --- name: geoms class: spaced ## Geoms <img src="assets/images/geoms.png" alt="drawing", width ="600"/> -- ```r p <- ggplot(iris) # scatterplot p+geom_point(aes(x=Sepal.Length,y=Sepal.Width)) # barplot p+geom_bar(aes(x=Sepal.Length)) # boxplot p+geom_boxplot(aes(x=Species,y=Sepal.Width)) # search help.search("^geom_",package="ggplot2") ``` --- name: aesth ## Aesthetics * Aesthetic mapping vs aesthetic parameter .pull-left-50[ ```r ggplot(iris)+ geom_point(aes(x=Sepal.Length, y=Sepal.Width, size=Petal.Length, alpha=Petal.Width, shape=Species, color=Species)) ``` <img src="slide_gg1_files/figure-html/unnamed-chunk-12-1.svg" style="display: block; margin: auto auto auto 0;" /> ] -- .pull-right-50[ ```r ggplot(iris)+ geom_point(aes(x=Sepal.Length, y=Sepal.Width), size=2, alpha=0.8, shape=15, color="steelblue") ``` <img src="slide_gg1_files/figure-html/unnamed-chunk-13-1.svg" style="display: block; margin: auto auto auto 0;" /> ] --- name: mul-geom ## Multiple geoms ```r ggplot(iris,aes(x=Sepal.Length,y=Sepal.Width))+ geom_point()+ geom_line()+ geom_smooth()+ geom_rug()+ geom_step()+ geom_text(data=subset(iris,iris$Species=="setosa"),aes(label=Species)) ``` <img src="slide_gg1_files/figure-html/unnamed-chunk-14-1.svg" style="display: block; margin: auto auto auto 0;" /> --- name: end_slide class: end-slide, middle count: false # Thank you. Questions? .end-text[ <p>R version 4.1.3 (2022-03-10)<br><p>Platform: x86_64-pc-linux-gnu (64-bit)</p><p>OS: Ubuntu 18.04.6 LTS</p><br> <hr> <span class="small">Built on : <i class='fa fa-calendar' aria-hidden='true'></i> 29-Apr-2022 at <i class='fa fa-clock-o' aria-hidden='true'></i> 07:09:44</span> <b>2022</b> • [SciLifeLab](https://www.scilifelab.se/) • [NBIS](https://nbis.se/) ]