WARNING: this is a work in progress!
the mapextrud R package allows to make extruded maps from sf objects (polygons or multipolygons). For the moment, it is only available on github.
Until a more advanced version is available on CRAN, you can install the package by writing this…
… and load the package like that.
The first thing to do before making an extruded map is to deform the basemap to give it a perspective effect. To do this, you can use the deform() function.
We Load an example background map on the US.
library(sf)
us <- st_read(system.file("us.gpkg", package="mapextrud"))
#> Reading layer `us' from data source `/home/nlambert/Documents/R/mapextrud/inst/us.gpkg' using driver `GPKG'
#> Simple feature collection with 49 features and 3 fields
#> geometry type: MULTIPOLYGON
#> dimension: XY
#> bbox: xmin: -2356114 ymin: -1295495 xmax: 2258154 ymax: 1558935
#> CRS: unknown
See below the original basemap
And here, the deformed basemap.
To better perceive the deformation, you can add a frame with the getframe() function
basemap <- deform(us)
frame <- deform(getframe(us))
plot(st_geometry(frame), col="#e1e5eb", border = "#99aed1", lwd=0.4)
plot(st_geometry(basemap), col="#99aed1", border = "white", lwd=0.4, add = TRUE)
Notice that you can configure the deformation. The parameter flatten indicates the scaling in Y. The parameter rescale adjust the deformation of the top and bottom of the figure (c(1,1) = no deformation).
basemap <- deform(us, flatten=0.5, rescale = c(0.5, 3))
frame <- deform(getframe(us), flatten=0.5, rescale = c(0.5, 3))
plot(st_geometry(frame), col="#e1e5eb", border = "#99aed1", lwd=0.4)
plot(st_geometry(basemap), col="#99aed1", border = "white", lwd=0.4, add = TRUE)
It can also be useful to rotate the basemap with the rotate() function.
us2 <- rotate(us, 180)
basemap <- deform(us2)
frame <- deform(getframe(us2))
plot(st_geometry(frame), col="#e1e5eb", border = "#99aed1", lwd=0.4)
plot(st_geometry(basemap), col="#99aed1", border = "white", lwd=0.4, add = TRUE)
Now we’re ready to start extruding… To do this, we use the function - unsustainable suspensions - extrud(). Beware, this is still an experimental function. It has bugs and works very slowly. Sorry for that!
Find below a simple example with the default settings.
Of course, you can custom the map by changing colors (col) and heights (k). On the reprentation below, you will probably notice some imperfections. I hope to be able to fix them in the next version of the package.