class: center, middle, inverse, title-slide .title[ # Data Visualization ] .subtitle[ ## Chapter 3. Data Visualization in R ] .author[ ### Iñaki Úcar ] .institute[ ### Department of Statistics | uc3m-Santander Big Data Institute ] .institute[ ### Master in Computational Social Science ] .date[ ###
Licensed under Creative Commons Attribution
CC BY 4.0
Last generated: 2023-01-25
] --- class: base24 # Directory of Visualizations .footnote[Based on [The R Graph Gallery](https://r-graph-gallery.com/)] .pull-left[ - .distribution[[Distribution](ch3_1.html#3)].icons[ ![:scale 10%](assets/img/section/Violin150.png) ![:scale 10%](assets/img/section/Density150.png) ![:scale 10%](assets/img/section/Histogram150.png) ![:scale 10%](assets/img/section/Box1150.png) ![:scale 10%](assets/img/section/Joyplot150.png) ] - .correlation[[Correlation](ch3_2.html#3)].icons[ ![:scale 10%](assets/img/section/ScatterPlot150.png) ![:scale 10%](assets/img/section/Heatmap150.png) ![:scale 10%](assets/img/section/Correlogram150.png) ![:scale 10%](assets/img/section/BubblePlot150.png) ![:scale 10%](assets/img/section/ScatterConnected150.png) ![:scale 10%](assets/img/section/2dDensity150.png) ] - .ranking[[Ranking](ch3_3.html#3)].icons[ ![:scale 10%](assets/img/section/Bar150.png) ![:scale 10%](assets/img/section/Spider150.png) ![:scale 10%](assets/img/section/Wordcloud150.png) ![:scale 10%](assets/img/section/Parallel1150.png) ![:scale 10%](assets/img/section/Lollipop150.png) ![:scale 10%](assets/img/section/CircularBarplot150.png) ] - .part[[Part of a Whole](ch3_4.html#3)].icons[ ![:scale 10%](assets/img/section/GroupedRed150.png) ![:scale 10%](assets/img/section/Tree150.png) ![:scale 10%](assets/img/section/Doughnut150.png) ![:scale 10%](assets/img/section/Pie150.png) ![:scale 10%](assets/img/section/Dendrogram150.png) ![:scale 10%](assets/img/section/CircularPacking150.png) ] ] .pull-right[ - .evolution[[Evolution](ch3_5.html#3)].icons[ ![:scale 10%](assets/img/section/Line150.png) ![:scale 10%](assets/img/section/Area150.png) ![:scale 10%](assets/img/section/StackedArea150.png) ![:scale 10%](assets/img/section/Stream150.png) ![:scale 10%](assets/img/section/Time150.gif) ] - .map[[Map](ch3_6.html#3)].icons[ ![:scale 10%](assets/img/section/Map150.png) ![:scale 10%](assets/img/section/Choropleth150.png) ![:scale 10%](assets/img/section/MapHexbin150.png) ![:scale 10%](assets/img/section/Cartogram150.png) ![:scale 10%](assets/img/section/ConnectedMap150.png) ![:scale 10%](assets/img/section/BubbleMap150.png) ] - .flow[[Flow](ch3_7.html#3)].icons[ ![:scale 10%](assets/img/section/Chord150.png) ![:scale 10%](assets/img/section/Network150.png) ![:scale 10%](assets/img/section/Sankey150.png) ![:scale 10%](assets/img/section/Arc150.png) ![:scale 10%](assets/img/section/Bundle150.png) ] - .other[[Other resources](ch3_8.html#3)].icons[ ![:scale 10%](assets/img/section/anim150.gif) ![:scale 10%](assets/img/section/Interactive150.png) ![:scale 10%](assets/img/section/Bad150.png) ![:scale 10%](assets/img/section/DataArt1150.png) ] ] --- class: ranking # Ranking .footnote[[< Contents](#2)] [![:scale 15%](assets/img/section/Bar150.png)](https://r-graph-gallery.com/barplot.html) [![:scale 15%](assets/img/section/Spider150.png)](https://r-graph-gallery.com/spider-or-radar-chart.html) [![:scale 15%](assets/img/section/Wordcloud150.png)](https://r-graph-gallery.com/wordcloud.html) [![:scale 15%](assets/img/section/Parallel1150.png)](https://r-graph-gallery.com/parallel-plot.html) [![:scale 15%](assets/img/section/Lollipop150.png)](https://r-graph-gallery.com/lollipop-plot.html) [![:scale 15%](assets/img/section/CircularBarplot150.png)](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 ![:scale 6%](assets/img/section/Bar150.png) 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 ![:scale 6%](assets/img/section/Bar150.png) 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 ![:scale 6%](assets/img/section/Bar150.png) 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 ![:scale 6%](assets/img/section/Bar150.png) 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 ![:scale 6%](assets/img/section/CircularBarplot150.png) 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 ![:scale 6%](assets/img/section/Lollipop150.png) 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 ![:scale 6%](assets/img/section/Lollipop150.png) 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 ![:scale 6%](assets/img/section/Lollipop150.png) 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 ![:scale 6%](assets/img/section/Parallel1150.png) 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 ![:scale 6%](assets/img/section/Parallel1150.png) 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;" /> ]