View source: R/spatial_functions.R
scalebar | R Documentation |
This function adds a scale to a projected map created with sp::plot.
scalebar(loc, length, unit = "km", division.cex = 0.8, ...)
loc |
A two value numeric vector. The longitude and latitude where the scale bar is to be. |
length |
numeric. The length of the divisions in the unit specified. |
unit |
character. Some options are "m" and "km". |
division.cex |
numeric. The size of the divisions. |
... |
Other arguments |
A sp::plot object with a scale.
For an unprojected map in R, we can use the map.scale
function in maps package. This is applicable to a map created not only by the maps package but also by other cartographic packages. However, in R, there is no scale bar applicable to a projected map. So, use it if your shapefile is projected. It should be noted that using scalebar for a decimal degree or the entire world is not logical because the function cannot convert units and retains them in the unconverted form in the current graphic device. Therefore, if necessary, users must project and coordinate the map appropriately prior to the execution of scalebar.
Taken from Auxiliary Cartographic Functions in R: North Arrow, Scale Bar, and Label with a Leader Arrow, Tanimura, 2007. For more information see here.
## Not run:
scalebar(c(-124, 26), length = 10000, unit = "km", division.cex = .8) ## Do not run.
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.