Created
January 11, 2021 14:27
-
-
Save MauricioCely/14c1ab8712daa8a3dda87de57cae73c8 to your computer and use it in GitHub Desktop.
Add scale bar and north indicator in map in GGPLOT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library("ggspatial") | |
library("rnaturalearth") | |
library("rnaturalearthdata") | |
world <- ne_countries(scale = "medium", returnclass = "sf") | |
########## Option 1 ########## | |
ggplot(data = world) + | |
geom_sf() + | |
annotation_scale(location = "bl", width_hint = 0.5) + | |
annotation_north_arrow(location = "bl", which_north = "true", | |
pad_x = unit(0.75, "in"), pad_y = unit(0.5, "in"), | |
style = north_arrow_fancy_orienteering) + | |
coord_sf(xlim = c(-102.15, -74.12), ylim = c(7.65, 33.97)) | |
########## Option 2 ########## | |
library("ggsn") | |
ggplot(data = world) + | |
geom_sf() + | |
ggsn::scalebar(x.min = -102.15, x.max = -74.12, | |
y.min = 7.65, y.max = 33.97, | |
location = "bottomleft", | |
dist = 500, dist_unit = "km", | |
transform = TRUE, model = "WGS84") + | |
ggsn::north(x.min = -102.15, x.max = -74.12, | |
y.min = 7.65, y.max = 33.97, | |
location = "topright", symbol = 15) + | |
coord_sf(xlim = c(-102.15, -74.12), ylim = c(7.65, 33.97)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment