Created
November 23, 2018 16:24
-
-
Save batpigandme/1c7e764a4109354e56036445e43b5532 to your computer and use it in GitHub Desktop.
Making a map of kiva loans with tmap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
suppressPackageStartupMessages(library(tidyverse)) | |
library(tmap) | |
data("World") | |
kiva_locations <- tibble::tribble( | |
~location, ~`number of loans`, ~pct_loans, ~iso_a3, | |
"Uganda", 25, 0.337837838, "UGA", | |
"Kenya", 8, 0.108108108, "KEN", | |
"Togo", 6, 0.081081081, "TGO", | |
"Rwanda", 5, 0.067567568, "RWA", | |
"Philippines", 5, 0.067567568, "PHL", | |
"Senegal", 4, 0.054054054, "SEN", | |
"Cambodia", 4, 0.054054054, "KHM", | |
"Congo (DRC)", 3, 0.040540541, "COD", | |
"Malawi", 2, 0.027027027, "MWI", | |
"Ghana", 2, 0.027027027, "GHA", | |
"Kyrgyzstan", 2, 0.027027027, "KGZ", | |
"Zimbabwe", 1, 0.013513514, "ZWE", | |
"United States", 1, 0.013513514, "USA", | |
"Bolivia", 1, 0.013513514, "BOL", | |
"Colombia", 1, 0.013513514, "COL", | |
"Lebanon", 1, 0.013513514, "LBN", | |
"Nicaragua", 1, 0.013513514, "NIC", | |
"Paraguay", 1, 0.013513514, "PRY", | |
"Sierra Leone", 1, 0.013513514, "SLE" | |
) | |
kiva_world <- World %>% | |
left_join(kiva_locations, by = "iso_a3") | |
tmap_mode("plot") | |
tmap_style("watercolor") | |
tm_shape(kiva_world) + | |
tm_polygons(col = 'number of loans', breaks = c(0,1,2,5,7,10,25) , | |
palette = "plasma", alpha = 0.8) + | |
tm_layout(title = "Kiva loans by country", | |
inner.margins = c(0, 0.1, 0, 0), | |
fontfamily = "Concourse T3", | |
bg.color = "lightblue") |
Author
batpigandme
commented
Nov 23, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment