Maps for life expectacy in Africa and South America
This cartography project was completed as an assignment for my Master’s program course, Environmental Data Science 233: Spatial Analysis. It was collaboration with G. Kumaishi.
Create a map of life expectancy for South America and Africa.
Create two separate maps for life expectancy data of South America and Africa using spData
and tmap
.
### Africa ###
world_africa <- world[world[["continent"]] == "Africa", ] # create a subset of the world dataset of just the African continent
lifeexp_africa <- tm_shape(world_africa) + # store map in order to combine
tm_polygons(col = "lifeExp", # select life expectancy data
palette = "YlOrBr", # Yellow Orange Brown color palette from RColorBrewer
style = "pretty", # familiar GIS discrete options available such as quantile, equal, jenks, etc.
title = "Life Expectancy (years)*", # legend title lives within tm_polygons
textNA = "No Data") + # converted "Missing" legend default to "No Data"
tm_layout(inner.margins = c(0.1, 0.1, 0.1, 0.1), # margins between 0-1 (bottom, left, top, right)
legend.title.size = 1,
legend.text.size = .8,
bg.color = "lightblue", # background color
title = "Africa") + # map title lives under tm_layouts
tm_compass(type = "4star", # other compass styles available
show.labels = 1, # specifies compass label options
size = 3,
position = c("right", "top")) +
tm_credits("Life expectancy data for the\nAfrican continent uses 5-year\nclassification breaks.\nSource: SpData \n \n*Note that the color scale differs\nbetween continents.", # credit data source including github link; \n creates text break
size = .5, # can't figure out how to make size bigger...
position = c("right", "bottom"),
align = "right", # only applicable if using multiple lines
width = NA) # 1 is the whole map width, NA is determined by width of text
lifeexp_africa
### South America ###
world_sa <- world[world[["continent"]] == "South America", ] # create a subset of the world dataset of just the South American continent
lifeexp_sa <- tm_shape(world_sa) + # store map in order to combine
tm_polygons(col = "lifeExp", # select life expectancy data
palette = "YlOrBr", # Yellow Orange Brown color palette from RColorBrewer
n = 5, # specify number of breaks
style = "pretty", # familiar GIS discrete options available such as quantile, equal, jenks, etc.
title = "Life Expectancy (years)*", # legend title lives within tm_polygons
textNA = "No Data") + # converted "Missing" legend default to "No Data"
tm_layout(inner.margins = c(0.1, 0.25, 0.1, 0.25), # margins between 0-1 (bottom, left, top, right)
legend.position = c("right", "bottom"),
legend.title.size = 1,
legend.text.size = .8,
bg.color = "lightblue", # background color
title = "South America") + # map title lives under tm_layouts
tm_compass(type = "4star", # other compass styles available
show.labels = 1, # specifies compass label options
size = 3,
position = c("right", "top")) +
tm_credits("Life expectancy data\nfor the South American continent uses\n2-year classification breaks.\nSource: SpData \n \n*Note that the color scale differs\nbetween continents.", # credit data source including github link; \n creates text break
position = c("left", "bottom"),
align = "left",
size = .5) +
tm_credits("", # explain varying color scales b/w two continents; \n creates text break
position = c("right", "bottom"),
align = "right",
size = .3)
lifeexp_sa
Combine the two maps using tmap_arrange
to compare and contrast life expectancy rates.
combined_lifeexp <- tmap_arrange(lifeexp_sa,lifeexp_africa) # combine the two life expectancy maps using tmap_arrange
combined_lifeexp
This project was to practice creating maps in R using sf
, tmap
, and spData
packages.
For attribution, please cite this work as
Parish (2021, Oct. 15). Julia Parish: Cartography Assignment. Retrieved from juliaparish.github.io/posts/2021-10-15-lifeexpectancy/
BibTeX citation
@misc{parish2021cartography, author = {Parish, Grace Kumaishi, Julia}, title = {Julia Parish: Cartography Assignment}, url = {juliaparish.github.io/posts/2021-10-15-lifeexpectancy/}, year = {2021} }