class: center, middle, inverse, title-slide .title[ # Data Analysis and Visualization ] .subtitle[ ## Chapter 4. Advanced Visualization and Communication ] .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: map # Map .footnote[[< Contents](#2)] [](https://r-graph-gallery.com/map.html) [](https://r-graph-gallery.com/choropleth-map.html) [](https://r-graph-gallery.com/hexbin-map.html) [](https://r-graph-gallery.com/cartogram.html) [](https://r-graph-gallery.com/connection-map.html) [](https://r-graph-gallery.com/bubble-map.html) .bottom[Map] .bottom[Choropleth] .bottom[Hexbin map] .bottom[Cartogram] .bottom[Connection] .bottom[Bubble map] <br> .black.font120[ - Visualizaton of **geospatial data** - Usually, the map is just a reference - Sometimes, it **encodes** the information ] --- class: map # Map  Map .footnote[[< Contents](#2) | Many resources and examples at [**r-spatial.org**](https://r-spatial.org/)] .pull-left-mod[ ``` r world <- giscoR::gisco_get_countries() ggplot(world) + * geom_sf() ``` ] .pull-right-mod[ <img src="ch3_files/figure-html/map-1.png" style="display: block; margin: auto;" /> ] --- class: map # Map  Map .footnote[[< Contents](#2)] .pull-left-mod[ ``` r *usa <- sf::st_as_sf(maps::map( "state", plot=FALSE, fill=TRUE)) ggplot(usa) + geom_sf() ``` ] .pull-right-mod[ <img src="ch3_files/figure-html/map-usa-1.png" style="display: block; margin: auto;" /> ] --- class: map # Map  Map .footnote[[< Contents](#2)] .pull-left-mod[ ``` r africa <- giscoR::gisco_get_countries( * region="Africa") ggplot(africa) + geom_sf() ``` ] .pull-right-mod[ <img src="ch3_files/figure-html/map-africa-1.png" style="display: block; margin: auto;" /> ] --- class: map # Map  Map .footnote[[< Contents](#2) | See [**Coordinate Reference Systems**](https://en.wikipedia.org/wiki/Spatial_reference_system)] .pull-left-mod[ ``` r africa <- giscoR::gisco_get_countries( region="Africa") ggplot(africa) + geom_sf() + * coord_sf(xlim=c(-20, 50), * ylim=c(-40, 40)) ``` ] .pull-right-mod[ <img src="ch3_files/figure-html/map-africa-cut-1.png" style="display: block; margin: auto;" /> ] --- class: map # Map  Choropleth .footnote[[< Contents](#2)] .pull-left-mod[ ``` r africa <- giscoR::gisco_get_countries( region="Africa") |> * left_join( * africamonitor::am_data( * series="SP_POP_TOTL", * from=2021, to=2021), * by=c("ISO3_CODE"="ISO3")) ggplot(africa) + * geom_sf(aes(fill=SP_POP_TOTL)) + coord_sf(xlim=c(-20, 50), ylim=c(-40, 40)) + scale_fill_viridis_c() + labs(fill="Population") + theme(legend.position=c(0, 0), legend.justification=c(0, 0)) ``` ] .pull-right-mod[ <img src="ch3_files/figure-html/choropleth-1.png" style="display: block; margin: auto;" /> ] --- class: map # Map  Cartogram .footnote[[< Contents](#2)] .pull-left-mod[ ``` r africa <- giscoR::gisco_get_countries( region="Africa") |> left_join( africamonitor::am_data( series="SP_POP_TOTL", from=2021, to=2021), by=c("ISO3_CODE"="ISO3")) |> sf::st_transform(3857) |> * cartogram::cartogram_cont( * "SP_POP_TOTL", itermax=5) |> sf::st_transform(4326) ggplot(africa) + * geom_sf(aes(fill=SP_POP_TOTL)) + coord_sf(xlim=c(-20, 50), ylim=c(-40, 40)) + scale_fill_viridis_c() + labs(fill="Population") + theme(legend.position=c(0, 0), legend.justification=c(0, 0)) ``` ] .pull-right-mod[ <img src="ch3_files/figure-html/cartogram-1.png" style="display: block; margin: auto;" /> ] --- class: map # Map  Bubble map .footnote[[< Contents](#2)] .pull-left-mod[ ``` r africa <- giscoR::gisco_get_countries( region="Africa") |> left_join( africamonitor::am_data( series="SP_POP_TOTL", from=2021, to=2021), by=c("ISO3_CODE"="ISO3")) *centroids <- africa |> * sf::st_centroid() *ggplot(centroids) + geom_sf(data=africa) + * geom_sf(aes(size=SP_POP_TOTL)) + coord_sf(xlim=c(-20, 50), ylim=c(-40, 40)) + labs(size="Population") + theme(legend.position=c(0, 0), legend.justification=c(0, 0)) ``` ] .pull-right-mod[ <img src="ch3_files/figure-html/bubble-1.png" style="display: block; margin: auto;" /> ] --- class: map # Map  Connection .footnote[[< Contents](#2)] .pull-left-mod[ ``` r africa <- giscoR::gisco_get_countries( region="Africa") |> left_join( africamonitor::am_data( series="SP_POP_TOTL", from=2021, to=2021), by=c("ISO3_CODE"="ISO3")) centroids <- africa |> sf::st_centroid() *lines <- centroids |> * sf::st_union() |> * sf::st_cast("LINESTRING") *ggplot(lines) + geom_sf(data=africa) + geom_sf(aes(size=SP_POP_TOTL), data=centroids) + * geom_sf() + coord_sf(xlim=c(-20, 50), ylim=c(-40, 40)) + labs(size="Population") + theme(legend.position=c(0, 0), legend.justification=c(0, 0)) ``` ] .pull-right-mod[ <img src="ch3_files/figure-html/connection-1.png" style="display: block; margin: auto;" /> ] --- class: map # Map  Hexbin map .footnote[[< Contents](#2)] .pull-left-mod[ ``` r esp <- mapSpain::esp_get_country() *hexccaa <- mapSpain::esp_get_hex_ccaa() *ggplot(hexccaa) + geom_sf(data=esp) + * geom_sf(aes(fill=codauto), alpha=0.3, show.legend=FALSE) + geom_sf_text( aes(label=label), check_overlap=TRUE) + theme_void(base_size=16) ``` ] .pull-right-mod[ <img src="ch3_files/figure-html/hexbin-1.png" style="display: block; margin: auto;" /> ] --- class: map # Map  Hexbin map .footnote[[< Contents](#2)] .pull-left-mod[ ``` r esp <- mapSpain::esp_get_country() *hexprov <- mapSpain::esp_get_hex_prov() *ggplot(hexprov) + geom_sf(data=esp) + geom_sf(aes(fill=codauto), alpha=0.3, show.legend=FALSE) + geom_sf_text( aes(label=label), check_overlap=TRUE) + theme_void(base_size=16) ``` ] .pull-right-mod[ <img src="ch3_files/figure-html/hexbin-prov-1.png" style="display: block; margin: auto;" /> ] --- class: map # Map  Hexbin map .footnote[[< Contents](#2)] .pull-left-mod[ ``` r esp <- mapSpain::esp_get_country() *gridprov <- mapSpain::esp_get_grid_prov() *ggplot(gridprov) + geom_sf(data=esp) + geom_sf(aes(fill=codauto), alpha=0.3, show.legend=FALSE) + geom_sf_text( aes(label=label), check_overlap=TRUE) + theme_void(base_size=16) ``` ] .pull-right-mod[ <img src="ch3_files/figure-html/hexbin-prov-grid-1.png" style="display: block; margin: auto;" /> ]