Social Analytics and Strategic Intelligence

Session 2: Maps

1 Exercise 1

## Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE
sf::st_layers(linkWorld_gpkg) # a link to github data
## Driver: GPKG 
## Available layers:
##       layer_name geometry_type features fields crs_name
## 1 countryBorders                    252      1   WGS 84
## 2     riverLines                     98      2   WGS 84
## 3     cityPoints         Point      610      3   WGS 84
countries=read_sf(linkWorld_gpkg,layer="countryBorders")
rivers=read_sf(linkWorld_gpkg,layer="riverLines")
cities=read_sf(linkWorld_gpkg,layer="cityPoints")
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.3.2
baseLayer=ggplot(data=countries)  + geom_sf(fill='grey90') + theme_light()
final=baseLayer + geom_sf(data=rivers, color='blue') + geom_sf(data=cities, color='red') 
final

2 Exercise 2

## Driver: GPKG 
## Available layers:
##   layer_name geometry_type features fields crs_name
## 1     border       Polygon        1      1   WGS 84
## 2     rivers                      5      2   WGS 84
## 3     cities         Point        8      3   WGS 84
baseLayer=ggplot(data=peru)  + geom_sf(fill='grey90') + theme_light()
final=baseLayer + geom_sf(data=peru_rivers, color='blue') + geom_sf(data=peru_cities, color='red') 
final

3 Exercise 3

## Driver: GPKG 
## Available layers:
##   layer_name geometry_type features fields              crs_name
## 1   airports         Point      197     18 Peru96 / UTM zone 19S
## 2     border       Polygon        1      1 Peru96 / UTM zone 19S
## 3     rivers                      5      2 Peru96 / UTM zone 19S
## 4     cities         Point        8      3 Peru96 / UTM zone 19S
baseLayer=ggplot(data=peru)  + geom_sf(fill='grey90') + theme_light()
final=baseLayer + geom_sf(data=peru_rivers, color='blue')  + geom_sf(data=peru_air, color='black') + geom_sf(data=peru_cities, color='red') +
  coord_sf(datum = st_crs(peru))
final

4 Exercise 4

## Driver: GPKG 
## Available layers:
##   layer_name geometry_type features fields                      crs_name
## 1  countries                     31      4 WGS 84 / Equal Earth Americas
## 2  centroids         Point       31      4 WGS 84 / Equal Earth Americas
library(ggplot2)
baseLayer=ggplot(data=ame)  + geom_sf(fill='grey90') + theme_light() 
final=baseLayer + geom_sf(data=ame_cen,aes(color=Total_ei5_cat),size=2+ame_cen$Total_ei5) +
    guides(size=NULL) +
  coord_sf(datum = st_crs(ame))

final

5 Challenge

## Driver: GPKG 
## Available layers:
##   layer_name geometry_type features fields crs_name
## 1    after10                    179      3   WGS 84
## [1] "COUNTRY" "iso3"    "after10" "geom"
ggplot(data=fragil) + theme_light() +
    geom_sf(aes(fill = after10), color=NA)