Last active
January 24, 2022 11:14
-
-
Save rCarto/0c735ccbe09884fb8ee6bac7e457cac8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
library(rnaturalearth) | |
library(mapsf) | |
library(fisheye) | |
ct <- ne_download(scale = 50, returnclass = "sf") | |
oc <- ne_download(type = "ocean", category = "physical", | |
scale = 50, returnclass = "sf") | |
x <- st_transform(ct, "+proj=natearth2") | |
z <- st_transform(oc, "+proj=natearth2") | |
mf_export(z, "initial.png", theme = "green") | |
mf_map(z, col = "white", border ="white", add = T) | |
mf_map(x, col = "lightblue", border = "white", lwd = .7, add = T) | |
mf_map(x, "POP_EST", "prop", border = "grey80", | |
inches = .3, leg_title = "Population", leg_frame = T) | |
mf_title("Original Map") | |
dev.off() | |
xCHN <- fisheye(x = x, centre = x[x$ADM0_A3 %in% "CHN",], k = 6) | |
zCHN <- fisheye(x = z, centre = x[x$ADM0_A3 %in% "CHN",], k = 6) | |
mf_export(zCHN, "china.png", theme = "green") | |
mf_map(zCHN, col = "white", border ="white", add = T) | |
mf_map(xCHN, col = "lightblue", border = "white", lwd = .7, add = T) | |
mf_map(xCHN, "POP_EST", "prop", border = "grey80", | |
inches = .3, leg_title = "Population", leg_frame = T) | |
mf_title("Transformed map, center = China") | |
dev.off() | |
xNGA <- fisheye(x = x, centre = x[x$ADM0_A3 %in% "NGA",], k = 6) | |
zNGA <- fisheye(x = z, centre = x[x$ADM0_A3 %in% "NGA",], k = 6) | |
mf_export(zNGA, "nigeria.png", theme = "green") | |
mf_map(zNGA, col = "white", border ="white", add = T) | |
mf_map(xNGA, col = "lightblue", border = "white", lwd = .7, add = T) | |
mf_map(xNGA, "POP_EST", "prop", border = "grey80", | |
inches = .3, leg_title = "Population", leg_frame = T) | |
mf_title("Transformed map, center = Nigeria") | |
dev.off() | |
xCHE <- fisheye(x = x, centre = x[x$ADM0_A3 %in% "CHE",], k = 6) | |
zCHE <- fisheye(x = z, centre = x[x$ADM0_A3 %in% "CHE",], k = 6) | |
mf_export(zCHE, "switzerland.png", theme = "green") | |
mf_map(zCHE, col = "white", border ="white", add = T) | |
mf_map(xCHE, col = "lightblue", border = "white", lwd = .7, add = T) | |
mf_map(xCHE, "POP_EST", "prop", border = "grey80", | |
inches = .3, leg_title = "Population", leg_frame = T) | |
mf_title("Transformed map, center = Switzerland") | |
dev.off() |
A possible workflow could be:
- download covid data at country level, with ISO3 country codes
- import the dataset as a data.frame
- merge the country sf object (x here) and the covid data.frame using the relevant common variables (iso3 something...)
- create the map (see https://riatelab.github.io/mapsf/ for how to use mapsf)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to input other data to show on the map, like the number of infected COVI-19 in each country, thanks.