Scale bar #119
Scale bar
#119
-
Is it possible to add a scale bar to plots, as in terra? f <- system.file("ex/elev.tif", package="terra") |
Beta Was this translation helpful? Give feedback.
Answered by
dieghernan
Oct 30, 2023
Replies: 1 comment
-
Yes, it is possible via # Your example
library(terra)
#> terra 1.7.55
f <- system.file("ex/elev.tif", package = "terra")
r <- rast(f)
plot(r)
sbar(10, c(6.3, 50)) # With tidyterra and ggspatial
library(tidyterra)
library(ggplot2)
library(ggspatial)
ggplot() +
geom_spatraster(data = r) +
scale_fill_terrain_c() +
annotation_scale(style = "ticks") Or you may give a try to library(tmap)
#> Breaking News: tmap 3.x is retiring. Please test v4, e.g. with
#> remotes::install_github('r-tmap/tmap')
tm_shape(r) +
tm_raster(palette = terrain.colors(10, rev = TRUE)) +
tm_layout(legend.position = c("right", "TOP")) +
tm_scale_bar() Created on 2023-10-30 with reprex v2.0.2 |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
dieghernan
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, it is possible via
ggspatial
package:Or you may give a try to
tmap
package, that is a complete different plotting system but provides great support for additional elements of a map such as scale bars and orientation arrows, see: