{"word_count": 932, "character_count": 7157}
A new version of the cartography package (v2.0.1) has arrived on CRAN.cartography allows various cartographic representations such as proportional symbols, chroropleth, typology, flows or discontinuities maps. It also offers several features enhancing the graphic presentation of maps like cartographic palettes, layout elements (scale, north arrow, title...), labels, legends or access to some cartographic APIs.Up to version 1.4.2 cartography was mainly based on sp and rgeos for its spatial data management and geoprocessing operations. These dependencies have been as much as possible replaced by sf functions since version 2.0.0.Most functions are kept unchanged except for the addition of an x argument used to take sf objects as inputs.See the NEWS file for the full list of changes and see sf README in case of installation problems with sf.Use Case ExamplesHere are some use case examples of the package. The first data set (North Carolina SIDS data set) is embedded in the sf package and the second one is embedded in cartography but of course, one can use any geospatial vector data file. The following scrips are also hosted on this gist.Proportional Symbols# load librarieslibrary(sf)library(cartography)## Import# get the path to the shapefile embedded in sf packageshapepath &#60;- system.file("shape/nc.shp", package="sf")# import the shapefilenc &#60;- st_read(shapepath)# change the projection of the mapnc &#60;- st_transform(nc, 3857)# get a figure ratio adapted to the basemapfigdim &#60;- getFigDim(x = nc, width = 800, mar = c(0,0,1.2,0), res = 100)## Proportionnal symbols map# png(filename = "map1.png", width = figdim[1], height = figdim[2], #     res = 100)# set figure marginspar(mar = c(0,0,1.2,0))# display the North Carolina countiesplot(st_geometry(nc), col = "khaki4", border = "khaki3",      bg = "lemonchiffon")# add the number of birthpropSymbolsLayer(x = nc,var = "BIR74", inches = 0.2,                  col = "lightslategrey",                 legend.title.txt = "N. of live births",                  legend.pos = 'topleft')# add a title and layoutlayoutLayer(title = "Births in North Carolina, 1974-1978",              theme = "sand.pal", frame =F, north = TRUE, sources = "",            author = "North Carolina SIDS data set", scale = 50)# dev.off()[caption id="attachment_1216" align="aligncenter" width="800"] click to enlarge[/caption]It is now possible to define a specific location for the legend (x,y, coordinates on the map) an to specify reference values for symbols:## Proportionnal symbols map with a custom legend# png(filename = "map2.png", width = figdim[1], height = figdim[2], #     res = 100)# set figure marginspar(mar = c(0,0,1.2,0))# display the North Carolina countiesplot(st_geometry(nc), col = "khaki4", border = "khaki3",      bg = "lemonchiffon")# add the number of birth (with no legend)propSymbolsLayer(x = nc,var = "BIR74", inches = 0.2,                  col = "lightslategrey",                 legend.title.txt = "N. of live births",                  legend.pos = 'n')# add a custom legendlegendCirclesSymbols(pos = c(-9205821, 4062698),                      title.txt = "N. of live births",                      var = c(250, 4000, 10000, 21590),                      inches = 0.2,                      col = "lightslategrey")# add a title and layoutlayoutLayer(title = "Births in North Carolina, 1974-1978",             theme = "sand.pal", frame =F, north = TRUE, sources = "",             author = "North Carolina SIDS data set", scale = 50)# dev.off()[caption id="attachment_1221" align="aligncenter" width="800"] click to enlarge[/caption]Proportional and Choropleth Symbols## Proportional and Choropleth Symbols Layer# png(filename = "map3.png", width = figdim[1], height = figdim[2],#     res = 100)# compute the sudden infant deaths per 1000 birthsnc$share &#60;- 100000 * nc$SID74 / nc$BIR74# quantization breaks of the ratebks &#60;- getBreaks(v = nc$share, method = "quantile", nclass = 5)# correct the breaks to use the global rate as limit of class global_rate &#60;- sum(nc$SID74) * 100000 / sum(nc$BIR74)bks[4] &#60;- global_rate# get a color palettecols &#60;- carto.pal(pal1 = "green.pal", n1 = 3, pal2 = "wine.pal", n2 = 2)# set figure marginspar(mar = c(0,0,1.2,0))# display the North Carolina countiesplot(st_geometry(nc), col = "khaki4", border = "khaki3",      bg = "lemonchiffon")# display circlespropSymbolsChoroLayer(x = nc,var = "BIR74", inches = 0.2,                      var2 = "share", breaks = bks, col = cols,                       legend.var.title.txt = "N. of live births",                       legend.var.pos = 'bottomleft',                       legend.var2.values.rnd = 0,                      legend.var2.pos = "topleft",                       legend.var2.title.txt = "Sudden infant death syndrome rate*")# add a title and layoutlayoutLayer(title = "Sudden Infant Death Syndrome in North Carolina, 1974-1978",             sources = "", north = TRUE, scale = 50,            theme = "sand.pal", frame = FALSE,             author = "*per 100,000 live births. Source: North Carolina SIDS data set")# dev.off()[caption id="attachment_1228" align="aligncenter" width="800"] click to enlarge[/caption]Labels# get the path to the shapefile embedded in cartography packageshapepath &#60;- system.file("shape/martinique.shp", package="cartography")# import the shapefilemtq &#60;- st_read(shapepath)# get a figure ratio adapted to the basemapfigdim &#60;- getFigDim(x = mtq, height = 800, mar = c(0,0,1.2,0), res = 100)## Label map (default)# png(filename = "map4.png", width = figdim[1], height = figdim[2], #     res = 100)# set figure marginspar(mar = c(0,0,1.2,0))# display Martinique communesplot(st_geometry(mtq), col = "khaki4", border = "khaki3",      bg = "aliceblue")# display labels (default)labelLayer(x = mtq, txt = "LIBGEO", cex = 1.2)# add a title and layoutlayoutLayer(title = "Martinique Communes",             sources = "", north = TRUE, scale = 5,            theme = "sand.pal", frame = FALSE,             author = "INSEE, 2016")# dev.off()[caption id="attachment_1223" align="aligncenter" width="664"] click to enlarge[/caption]It is now possible to add a halo around labels and to avoid overlapping:## Label map (custom)# png(filename = "map5.png", width = figdim[1], height = figdim[2], #     res = 100)# set figure marginspar(mar = c(0,0,1.2,0))# display Martinique communesplot(st_geometry(mtq), col = "khaki4", border = "khaki3",      bg = "aliceblue")# display labels (default)labelLayer(x = mtq, txt = "LIBGEO", cex = 1.2,           overlap = FALSE, show.lines = FALSE,            halo = TRUE, bg = "white", r = 0.15)# add a title and layoutlayoutLayer(title = "Martinique Communes",             sources = "", north = TRUE, scale = 5,            theme = "sand.pal", frame = FALSE,             author = "INSEE, 2016")# dev.off()[caption id="attachment_1224" align="aligncenter" width="664"] click to enlarge[/caption]Cartographic MixScript of the cartographic mixQuestions? Issues?The stable release of the package is on CRAN and the development version is hosted on GitHub.Feel free to submit issues, report bugs or ask questions here.