Description Usage Arguments Examples
Adds a scale bar to maps created with ggplot or ggmap.
1 2 3 4 5 6 7 | scalebar(data = NULL, location = "bottomright", dist = NULL,
dist_unit = NULL, transform = NULL, dd2km = NULL, model = NULL,
height = 0.02, st.dist = 0.02, st.bottom = TRUE, st.size = 5,
st.color = "black", box.fill = c("black", "white"),
box.color = "black", border.size = 1, x.min = NULL, x.max = NULL,
y.min = NULL, y.max = NULL, anchor = NULL, facet.var = NULL,
facet.lev = NULL, ...)
|
data |
the same |
location |
string indicating the scale bar's location in the plot. Possible options: "topright" (default), "bottomright", "bottomleft" and "topleft". |
dist |
distance to represent with each segment of the scale bar. |
dist_unit |
unit of measurement for |
transform |
If TRUE, it is assumed that coordinates are in decimal degrees. If FALSE, it assumed that they are in meters. |
dd2km |
deprecated. Use transform instead. |
model |
choice of ellipsoid model ("WGS84", "GRS80", "Airy", "International", "Clarke", or "GRS67") Used when transform is TRUE. |
height |
number between 0 and 1 to indicate the scale bar's height, as a proportion of the y axis. |
st.dist |
number between 0 and 1 to indicate the distance between the scale bar and the scale bar's text, as a proportion of the y axis. |
st.bottom |
logical. If TRUE (default) the scale bar's text is displayed at the bottom of the scale bar, if FALSE, it is displayed at the top. |
st.size |
number to indicate the scale bar's size. It is passed to |
st.color |
color of the scale bar's text. Default is black. |
box.fill |
fill color of the box. If vector of two colors, the two boxes are filled with a different color. Defaults to black and white. |
box.color |
color of the box's border. If vector of two colors, the borders of the two boxes are colored differently. Defaults to black. |
border.size |
number to define the border size. |
x.min |
if |
x.max |
if |
y.min |
if |
y.max |
if |
anchor |
named |
facet.var |
if faceting, character vector of variable names used for faceting. This is useful for placing the scalebar in only one facet and must be used together with |
facet.lev |
character vector with the name of one level for each variable in |
... |
further arguments passed to |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | ## Not run:
library(sf)
data(domestic_violence)
# Map in geographic coordinates
ggplot(domestic_violence, aes(fill = Scaled)) +
geom_sf() +
scalebar(domestic_violence, dist = 4, dist_unit = "km",
transform = TRUE, model = "WGS84") +
blank() +
scale_fill_continuous(low = "#fff7ec", high = "#7F0000")
# Map in projected coordinates
domestic_violence2 <- st_transform(domestic_violence, 31983)
ggplot(domestic_violence2, aes(fill = Scaled)) +
geom_sf() +
scalebar(domestic_violence2, dist = 4, dist_unit = "km",
transform = FALSE, model = "WGS84") +
blank() +
scale_fill_continuous(low = "#fff7ec", high = "#7F0000")
## End(Not run)
|
Loading required package: ggplot2
Loading required package: grid
Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.