Skip to content

Scale bar #119

Answered by dieghernan
danbebber asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, it is possible via ggspatial package:

# 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 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:

library(tmap)
#> Breaking News: tmap 3.x is retiring. Please test v4, e.g. with
#> remotes::install_github('r-tmap/tmap')

tm_shape(

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by dieghernan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
📊 ggplot2 Issues related with the implementation of ggplot2 functionalities ❔ q&a Questions on the usage of tidyterra
2 participants
Converted from issue

This discussion was converted from issue #118 on October 30, 2023 21:12.