basic example of mapsf

Author

math4mad

Code
library(mapsf)
Warning: package 'mapsf' was built under R version 4.2.3
Code
# Import the sample dataset
mtq <- mf_get_mtq()
# Plot the base map
mf_map(x = mtq)
# Plot proportional symbols
mf_map(x = mtq, var = "POP", type = "prop", leg_pos = "topright")
# Plot a map layout
mf_layout(
  title = "Population in Martinique",
  credits = "T. Giraud; Sources: INSEE & IGN, 2018"
)

Code
# Export a map with a theme and extra margins
mf_theme("green")
mf_export(
  x = mtq, filename = "mtq.png",
  width = 600, res = 120,
  expandBB = c(0, 0, 0, .3)
)
Warning in grSoftVersion(): unable to load shared object '/Library/Frameworks/R.framework/Resources/modules//R_X11.so':
  dlopen(/Library/Frameworks/R.framework/Resources/modules//R_X11.so, 0x0006): Library not loaded: /opt/X11/lib/libSM.6.dylib
  Referenced from: <BBB44505-4BB3-30FA-9ED6-ABC69D534041> /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/modules/R_X11.so
  Reason: tried: '/opt/X11/lib/libSM.6.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/X11/lib/libSM.6.dylib' (no such file), '/opt/X11/lib/libSM.6.dylib' (no such file), '/Library/Frameworks/R.framework/Resources/lib/libSM.6.dylib' (no such file), '/Library/Java/JavaVirtualMachines/jdk-17.0.1+12/Contents/Home/lib/server/libSM.6.dylib' (no such file)
Warning in cairoVersion(): unable to load shared object '/Library/Frameworks/R.framework/Resources/library/grDevices/libs//cairo.so':
  dlopen(/Library/Frameworks/R.framework/Resources/library/grDevices/libs//cairo.so, 0x0006): Library not loaded: /opt/X11/lib/libXrender.1.dylib
  Referenced from: <25AEF222-E381-3C27-AC91-0E12B2DF269A> /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/grDevices/libs/cairo.so
  Reason: tried: '/opt/X11/lib/libXrender.1.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/X11/lib/libXrender.1.dylib' (no such file), '/opt/X11/lib/libXrender.1.dylib' (no such file), '/Library/Frameworks/R.framework/Resources/lib/libXrender.1.dylib' (no such file), '/Library/Java/JavaVirtualMachines/jdk-17.0.1+12/Contents/Home/lib/server/libXrender.1.dylib' (no such file)
Warning in png(filename, width = fd[1], height = fd[2], res = res, type =
"cairo-png", : failed to load cairo DLL
Code
# Plot a shadow
mf_shadow(mtq, col = "grey10", add = TRUE)
# Plot a choropleth map
mf_map(
  x = mtq, var = "MED", type = "choro",
  pal = "Dark Mint",
  breaks = "quantile",
  nbreaks = 6,
  leg_title = "Median Income\n(euros)",
  leg_val_rnd = -2,
  add = TRUE
)
# Start an inset map
mf_inset_on(x = "worldmap", pos = "right")
# Plot mtq position on a worldmap
mf_worldmap(mtq, col = "#0E3F5C")
# Close the inset
mf_inset_off()
# Plot a title
mf_title("Wealth in Martinique, 2015")
# Plot credits
mf_credits("T. Giraud\nSources: INSEE & IGN, 2018")
# Plot a scale bar
mf_scale(size = 5)
# Plot a north arrow
mf_arrow("topleft")

Code
dev.off()
null device 
          1 
Code
mtq <- mf_get_mtq()
head(mtq)
Simple feature collection with 6 features and 7 fields
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: 695444 ymin: 1598818 xmax: 717731 ymax: 1645182
Projected CRS: WGS 84 / UTM zone 20N
  INSEE_COM              STATUS            LIBGEO  POP   MED CHOM  ACT
1     97201 Simple municipality L'Ajoupa-Bouillon 1902 13633  254  801
2     97202 Simple municipality Les Anses-d'Arlet 3737 14558  425 1659
3     97203 Simple municipality      Basse-Pointe 3357 14456  400 1395
4     97204 Simple municipality         Le Carbet 3683 18847  285 1568
5     97205 Simple municipality       Case-Pilote 4458 21005  347 2096
6     97206 Simple municipality        Le Diamant 5976 19704  430 2654
                            geom
1 MULTIPOLYGON (((699261 1637...
2 MULTIPOLYGON (((709840 1599...
3 MULTIPOLYGON (((697602 1638...
4 MULTIPOLYGON (((702229 1628...
5 MULTIPOLYGON (((698805 1621...
6 MULTIPOLYGON (((709840 1599...
Code
mf_map(mtq)
mf_map(mtq, var = c("POP", "MED"), type = "prop_choro")