class: center, middle, inverse, title-slide .title[ # Data Analysis and Visualization ] .subtitle[ ## Chapter 3. Exploratory Data Analysis in R ] .author[ ### Iñaki Úcar ] .institute[ ### Department of Statistics | uc3m-Santander Big Data Institute ] .institute[ ### Bachelor in Data and Business Analytics ] .date[ ###
Licensed under Creative Commons Attribution
CC BY 4.0
Last generated: 2025-09-06
] --- class: base24 # Catalog of Graphs and Applications .footnote[Based on [The R Graph Gallery](https://r-graph-gallery.com/)] .pull-left[ - .distribution[[Distribution](ch3_1.html#3)].icons[      ] - .correlation[[Correlation](ch3_2.html#3)].icons[       ] - .ranking[[Ranking](ch3_3.html#3)].icons[       ] - .part[[Part of a Whole](ch3_4.html#3)].icons[       ] ] .pull-right[ - .evolution[[Evolution](ch3_5.html#3)].icons[      ] - .map[[Map](ch3_6.html#3)].icons[       ] - .flow[[Flow](ch3_7.html#3)].icons[      ] - .other[[Other resources](ch3_8.html#3)].icons[     ] ] --- class: ranking # Ranking .footnote[[< Contents](#2)] [](https://r-graph-gallery.com/barplot.html) [](https://r-graph-gallery.com/spider-or-radar-chart.html) [](https://r-graph-gallery.com/wordcloud.html) [](https://r-graph-gallery.com/parallel-plot.html) [](https://r-graph-gallery.com/lollipop-plot.html) [](https://r-graph-gallery.com/circular-barplot.html) .bottom[Barplot] .bottom[Spider/radar] .bottom[Wordcloud] .bottom[Parallel] .bottom[Lollipop] .bottom[Circular barplot] <br> .black.font120[ - Visualization of the **ranking of a categorical variable** - Based on some other numerical variable - **Sort your data!** ] --- class: ranking # Ranking  Barplot .footnote[[< Contents](#2)] .pull-left-mod[ ``` r ggplot(mpg) + aes(class) + * geom_bar() + labs(x=NULL) ``` ] .pull-right-mod[ <img src="ch3_files/figure-html/barplot-1.png" style="display: block; margin: auto;" /> ] --- class: ranking # Ranking  Barplot .footnote[[< Contents](#2)] .pull-left-mod[ ``` r mpg |> count(drv, class, name="count") |> ggplot() + * aes(count, class) + * geom_col() + labs(y=NULL) ``` ] .pull-right-mod[ <img src="ch3_files/figure-html/barplot-col-1.png" style="display: block; margin: auto;" /> ] --- class: ranking # Ranking  Barplot .footnote[[< Contents](#2)] .pull-left-mod[ ``` r mpg |> count(drv, class, name="count") |> ggplot() + * aes(count, reorder(class, count, sum)) + geom_col() + labs(y=NULL) ``` ] .pull-right-mod[ <img src="ch3_files/figure-html/barplot-order-1.png" style="display: block; margin: auto;" /> ] --- class: ranking # Ranking  Barplot .footnote[[< Contents](#2)] .pull-left-mod[ ``` r mpg |> count(drv, class, name="count") |> ggplot() + aes(count, reorder(class, count, sum)) + * geom_col(aes(fill=drv)) + labs(y=NULL) + theme(legend.position="top") ``` ] .pull-right-mod[ <img src="ch3_files/figure-html/barplot-color-1.png" style="display: block; margin: auto;" /> ] --- class: ranking # Ranking  Circular Barplot .footnote[[< Contents](#2)] .pull-left-mod[ ``` r mpg |> count(drv, class, name="count") |> ggplot() + aes(count, reorder(class, count, sum)) + geom_col(aes(fill=drv)) + * coord_polar(theta="y") + labs(y=NULL) + theme(legend.position="top") ``` ] .pull-right-mod[ <img src="ch3_files/figure-html/barplot-circular-1.png" style="display: block; margin: auto;" /> ] --- class: ranking # Ranking  Lollipop .footnote[[< Contents](#2)] .pull-left-mod[ ``` r mpg |> count(drv, class, name="count") |> ggplot() + aes(count, reorder(class, count, sum)) + * geom_segment(aes(xend=0, yend=class)) + * geom_point(size=3) + labs(y=NULL) ``` ] .pull-right-mod[ <img src="ch3_files/figure-html/lollipop-1.png" style="display: block; margin: auto;" /> ] --- class: ranking # Ranking  Lollipop .footnote[[< Contents](#2)] .pull-left-mod[ ``` r mpg |> count(drv, class, name="count") |> ggplot() + aes(count, reorder(class, count, sum)) + * aes(color=drv) + geom_segment(aes(xend=0, yend=class)) + geom_point(size=3) + labs(y=NULL) + theme(legend.position=c(1, 0), legend.justification=c(1, 0)) ``` ] .pull-right-mod[ <img src="ch3_files/figure-html/lollipop-color-1.png" style="display: block; margin: auto;" /> ] --- class: ranking # Ranking  Lollipop .footnote[[< Contents](#2)] .pull-left-mod[ ``` r mpg |> count(drv, class, name="count") |> group_by(class) |> summarise(xmin = min(count), count = max(count)) |> ggplot() + aes(count, reorder(class, count, sum)) + * geom_segment(aes(xend=xmin, yend=class)) + geom_point(size=3) + * geom_point(aes(xmin), size=3) + labs(y=NULL) + * expand_limits(x=0) ``` ] .pull-right-mod[ <img src="ch3_files/figure-html/lollipop-minmax-1.png" style="display: block; margin: auto;" /> ] --- class: ranking # Ranking  Parallel .footnote[[< Contents](#2)] .pull-left-mod[ ``` r iris |> * tibble::rowid_to_column("id") |> gather("key", "value", -Species, -id) |> ggplot() + aes(key, value, color=Species) + geom_point(alpha=0.5) + * geom_line(aes(group=id), alpha=0.3) + scale_color_viridis_d() + labs(x=NULL) + theme(legend.position="top") ``` ] .pull-right-mod[ <img src="ch3_files/figure-html/parallel-1.png" style="display: block; margin: auto;" /> ] --- class: ranking # Ranking  Parallel .footnote[[< Contents](#2)] .pull-left-mod[ ``` r iris |> tibble::rowid_to_column("id") |> gather("key", "value", -Species, -id) |> * group_by(key) |> * mutate(value = scale(value)) |> ggplot() + aes(key, value, color=Species) + geom_point(alpha=0.5) + geom_line(aes(group=id), alpha=0.3) + scale_color_viridis_d() + * labs(x=NULL, y="Std. value") + theme(legend.position="top") ``` ] .pull-right-mod[ <img src="ch3_files/figure-html/parallel-scale-1.png" style="display: block; margin: auto;" /> ]