Skip to content

Instantly share code, notes, and snippets.

@rCarto
Last active January 24, 2022 11:14
Show Gist options
  • Select an option

  • Save rCarto/0c735ccbe09884fb8ee6bac7e457cac8 to your computer and use it in GitHub Desktop.

Select an option

Save rCarto/0c735ccbe09884fb8ee6bac7e457cac8 to your computer and use it in GitHub Desktop.

Revisions

  1. rCarto revised this gist Jan 21, 2022. No changes.
  2. rCarto created this gist Jan 21, 2022.
    52 changes: 52 additions & 0 deletions fisheye-world.R
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,52 @@
    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()