A new version of the
cartography package (v2.4.0) has arrived on CRAN.
waffleLayer()plots a “waffle map”. This kind of representation allows to plot several quantities on the same map.
ghostLayer()is a short function that plot an invisible layer with the extent of a spatial object. This function is useful to initiate a map with a specific extent.
library(sf) library(cartography) mtq <- st_read(system.file("gpkg/mtq.gpkg",
package="cartography")) target <- mtq[30, ] ghostLayer(target) plot(st_geometry(mtq), col = "gold2", add = TRUE)
hatchedLayer()plots a hatched layer, several patterns are available.
getPngLayer()import a PNG image and cut it using the shape of a spatial object.
wordcloudLayer()plots a word cloud adjusted to an sf object.
These 3 functions are well described by their creator, Diego Hernangómez, on his blog.
getTiles() gets map tiles from various tile servers.
- The function has gained caching capacities (through
forceDownloadarguments). Users can now cache tiles in a folder and reuse them across R sessions.
- More than 50 tile servers have been included and other can be added by users.
- It is possible to use Thunderforest tiles with an API key.
barscale() function plots a scale bar on a map, a new
unit argument has been added to plot the scale bar in meters, kilometers or miles.
Under the Hood
cartography does not use
rosm anymore to import map tiles. The package is working great but its maintainer, Dewey Dunnington, suggests that it will not evolve much and that other package will appear to replace it. Thus we have decided to use
slippymath and internal code to download tiles. A (positive) side effect of this replacement is a decrease in the indirect dependancies of
cartography appears to be robust to the changes introduced by the last
sf version (v0.9). This version takes into account the new representation of coordinate reference systems proposed by GDAL and PROJ. More information on this here.