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: evolution # Evolution .footnote[[< Contents](#2)] [![:scale 15%](assets/img/section/Line150.png)](https://r-graph-gallery.com/line-plot.html) [![:scale 15%](assets/img/section/Area150.png)](https://r-graph-gallery.com/area-chart.html) [![:scale 15%](assets/img/section/StackedArea150.png)](https://r-graph-gallery.com/stacked-area-graph.html) [![:scale 15%](assets/img/section/Stream150.png)](https://r-graph-gallery.com/streamgraph.html) [![:scale 15%](assets/img/section/Time150.gif)](https://r-graph-gallery.com/time-series.html) .bottom[Line plot] .bottom[Area] .bottom[Stacked area] .bottom[Stream chart] .bottom[Time series] <br> .black.font120[ - Visualization of the **evolution** of series - Individual data points are not important - When `x` is time -> **time series** ] --- class: evolution # Evolution ![:scale 6%](assets/img/section/Line150.png) Line plot .footnote[[< Contents](#2)] .pull-left-mod[ ```r ggstream::blockbusters |> filter(genre == "Action") |> ggplot() + aes(year, box_office) + * geom_line() ``` ] .pull-right-mod[ <img src="ch3_files/figure-html/line-1.png" style="display: block; margin: auto;" /> ] --- class: evolution # Evolution ![:scale 6%](assets/img/section/Area150.png) Area .footnote[[< Contents](#2)] .pull-left-mod[ ```r ggstream::blockbusters |> filter(genre == "Action") |> ggplot() + aes(year, box_office) + * geom_area() ``` ] .pull-right-mod[ <img src="ch3_files/figure-html/area-1.png" style="display: block; margin: auto;" /> ] --- class: evolution # Evolution ![:scale 6%](assets/img/section/Time150.gif) Time series .footnote[[< Contents](#2)] .pull-left-mod[ ```r ggstream::blockbusters |> * mutate(date = as.Date( * ISOdate(year, 1, 1))) |> filter(genre == "Action") |> ggplot() + * aes(date, box_office) + geom_line() ``` ] .pull-right-mod[ <img src="ch3_files/figure-html/line-time-1.png" style="display: block; margin: auto;" /> ] --- class: evolution # Evolution ![:scale 6%](assets/img/section/Time150.gif) Time series .footnote[[< Contents](#2)] .pull-left-mod[ ```r ggstream::blockbusters |> mutate(date = as.Date( ISOdate(year, 1, 1))) |> ggplot() + aes(date, box_office) + * geom_line(aes(color=genre)) ``` ] .pull-right-mod[ <img src="ch3_files/figure-html/line-color-1.png" style="display: block; margin: auto;" /> ] --- class: evolution # Evolution ![:scale 6%](assets/img/section/Time150.gif) Time series .footnote[[< Contents](#2)] .pull-left-mod[ ```r ggstream::blockbusters |> mutate(date = as.Date( ISOdate(year, 1, 1))) |> * mutate(genre = forcats::fct_reorder2( * genre, year, box_office)) |> ggplot() + aes(date, box_office) + geom_line(aes(color=genre)) ``` ] .pull-right-mod[ <img src="ch3_files/figure-html/line-order-1.png" style="display: block; margin: auto;" /> ] --- class: evolution # Evolution ![:scale 6%](assets/img/section/Time150.gif) Time series .footnote[[< Contents](#2)] .pull-left-mod[ ```r df <- ggstream::blockbusters |> mutate(date = as.Date( ISOdate(year, 1, 1))) text <- df |> group_by(genre) |> * slice(n()) ggplot(df) + aes(date, box_office, * color=genre) + geom_line() + * geom_text(aes(label=genre), text, hjust=-0.1) + * expand_limits( x=as.Date("2024-01-01")) + theme(legend.position="none") ``` ] .pull-right-mod[ <img src="ch3_files/figure-html/line-annotation-1.png" style="display: block; margin: auto;" /> ] --- class: evolution # Evolution ![:scale 6%](assets/img/section/StackedArea150.png) Stacked area .footnote[[< Contents](#2)] .pull-left-mod[ ```r ggstream::blockbusters |> mutate(date = as.Date( ISOdate(year, 1, 1))) |> ggplot() + aes(date, box_office) + * geom_area(aes(fill=genre)) ``` ] .pull-right-mod[ <img src="ch3_files/figure-html/area-fill-1.png" style="display: block; margin: auto;" /> ] --- class: evolution # Evolution ![:scale 6%](assets/img/section/Stream150.png) Streamchart .footnote[[< Contents](#2)] .pull-left-mod[ ```r ggstream::blockbusters |> mutate(date = as.Date( ISOdate(year, 1, 1))) |> ggplot() + aes(date, box_office) + * ggstream::geom_stream( aes(fill=genre), * type="ridge") ``` ] .pull-right-mod[ <img src="ch3_files/figure-html/stream-ridge-1.png" style="display: block; margin: auto;" /> ] --- class: evolution # Evolution ![:scale 6%](assets/img/section/Stream150.png) Streamchart .footnote[[< Contents](#2)] .pull-left-mod[ ```r ggstream::blockbusters |> mutate(date = as.Date( ISOdate(year, 1, 1))) |> ggplot() + aes(date, box_office) + ggstream::geom_stream( aes(fill=genre), * type="mirror") ``` ] .pull-right-mod[ <img src="ch3_files/figure-html/stream-mirror-1.png" style="display: block; margin: auto;" /> ] --- class: evolution # Evolution ![:scale 6%](assets/img/section/Stream150.png) Streamchart .footnote[[< Contents](#2)] .pull-left-mod[ ```r ggstream::blockbusters |> mutate(date = as.Date( ISOdate(year, 1, 1))) |> ggplot() + aes(date, box_office) + ggstream::geom_stream( aes(fill=genre), * type="proportional") ``` ] .pull-right-mod[ <img src="ch3_files/figure-html/stream-proportional-1.png" style="display: block; margin: auto;" /> ]