[英]horizontal legend in terra R package
對於terra
,我想將圖例水平放置在map下方。從help
看來,這可以通過將字符傳遞給legend
(例如legend = "bottomleft"
)或將列表傳遞給plg來完成,其中plg
來自基地-R 圖例 function。但是,對我來說這些都不起作用。 請參閱下面的代碼示例。
謝謝!
rm(list = ls())
library(terra)
f <- system.file("ex/elev.tif", package="terra")
r <- rast(f)
terra::plot(r)
terra::plot(r, legend = "bottomleft")
terra::plot(r, plg = list(horiz = TRUE))
terra::plot(r, plg = list(x = 6, y = 49.5, horiz = TRUE))
在所有情況下,生成的 map 如下所示:
編輯:通過將范圍傳遞給 plg,覆蓋 plot 軸限制之外的區域,圖例移動到正確的位置,但horiz = TRUE
仍然不旋轉它:
e <- c(5.6, 6.6, 49.2, 49.3)
terra::plot(r, plg = list(ext = e, horizontal = TRUE), mar = rep(4, 4))
查看gitHub 中的 terra 代碼,我找到了解決方案。 您需要通過plg
列表傳遞loc
和ext
arguments:
rm(list = ls())
library(terra)
library(RColorBrewer)
f <- system.file("ex/elev.tif", package="terra")
r <- rast(f)
e <- c(5.5, 7.0, 49.35, 49.38)
terra::plot(r, plg = list(ext = e, loc = "bottom"))
# Change color scale, range, ticks
terra::plot(r,
col = brewer.pal(7, "BrBG"), range = c(150, 500),
plg = list(ext = l_ext, loc = "bottom", title = "myvar",
at = c(150, 200, 250, 350, 450, 500)))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.