-
Notifications
You must be signed in to change notification settings - Fork 125
Open
Labels
LayoutIssues related to map layout (including many maps, facets, positions, etc.)Issues related to map layout (including many maps, facets, positions, etc.)LegendsIssues related to legendsIssues related to legends
Description
I want to position north arrow at the center of the scalebar. I am using the following code:
library(sf)
library(tmap)
library(terra)
r <- rast(system.file("ex/elev.tif", package="terra"))
states <- st_read(system.file("ex/lux.shp", package="terra"))
# make some bbox magic
bbox_new <- st_bbox(r) # current bounding box
xrange <- bbox_new$xmax - bbox_new$xmin # range of x values
yrange <- bbox_new$ymax - bbox_new$ymin # range of y values
bbox_new[1] <- bbox_new[1] - (0.05 * xrange) # xmin - left
bbox_new[3] <- bbox_new[3] + (0.05 * xrange) # xmax - right
bbox_new[2] <- bbox_new[2] - (0.05 * yrange) # ymin - bottom
bbox_new[4] <- bbox_new[4] + (0.05 * yrange) # ymax - top
bbox_new <- bbox_new %>% # take the bounding box ...
st_as_sfc() # ... and make it a sf polygon
tm_shape(r, bbox = bbox_new) +
tm_raster(col.scale = tm_scale_continuous(
values = "viridis"), # color palette;
col.legend = tm_legend(title = "Legend", frame.lwd = 0,
position = c("LEFT", "BOTTOM"))) +
tm_shape(states) +
tm_borders() +
tm_compass(position = tm_pos_in(pos.h="right", pos.v="top", align.h="center"), size = 1, text.size = 1) +
tm_scalebar(text.size = 1, breaks = c(0, 8, 16), position = tm_pos_in(pos.h="right", pos.v="top", align.h="center"))
As you can see from the output map, the north arrow is slightly shifted towards right of scalebar. How can I position the north arrow at the centre of scalebar? My expected output is
Metadata
Metadata
Assignees
Labels
LayoutIssues related to map layout (including many maps, facets, positions, etc.)Issues related to map layout (including many maps, facets, positions, etc.)LegendsIssues related to legendsIssues related to legends