如何在tmap的tm_facets中只添加一次compass和scale_bar?

问题描述 投票:0回答:1

我只想在使用

tm_facets
时添加指南针和scale_bar一次。这是示例代码

library(tmap)
library(stars)
library(terra)

#Read some data
tif = system.file("tif/L7_ETMs.tif", package = "stars")
x = rast(tif)

#Plot it using tmap r package
tm_shape(x) +
  tm_raster(style="quantile")+
  tm_facets(nrow = 3) +
  tm_layout(panel.labels = names(x), 
            legend.outside=T, legend.outside.position = "right",
            legend.position= c("center", "center"),
            legend.text.size = 1,
            legend.format = list(digits = 2, text.separator = "-"))+
  tm_compass(position = c("RIGHT", "BOTTOM"))+
  tm_scale_bar(text.size = 1, position = c("RIGHT", "BOTTOM"))

Rplot

正如您在输出中看到的,所有方面都有指南针和比例尺。如何仅在一个方面添加指南针和比例尺?

r terra tmap
1个回答
0
投票

我可以通过这篇文章

的帮助来添加单个指南针和scale_bar
library(tmap)
library(stars)
library(terra)

#Read some data
tif = system.file("tif/L7_ETMs.tif", package = "stars")
x = terra::rast(tif)

#Plot it using tmap r package
tm_shape(x) + tm_raster(style="quantile") + tm_facets(nrow = 3) +
  tm_layout(panel.labels = names(x), attr.outside = T, attr.outside.position = "bottom", attr.just = "right",
            legend.outside = T, legend.outside.position = "right",
            legend.position = c("left", "top"),
            legend.text.size = 0.8, legend.title.size = 0.9,
            legend.format = list(digits = 2, text.separator = "-"))+
  tm_compass(position = c("left", "top"))+
  tm_scale_bar(text.size = 1, position = c("RIGHT", "top"))

© www.soinside.com 2019 - 2024. All rights reserved.