[英]R tmap modify legends dynamically to prevent overlapping legend values
有沒有辦法動態防止 tmap 中圖例中的重疊值?
拿這個例子:
library(tmap)
data("World")
tm_shape(World) +
tm_polygons("HPI", n=7)
圖例沒有說明 15、20、25、30、35 或 40 屬於哪個類別值。
一種解決方案是這樣的:
tm_shape(World) +
tm_polygons("HPI", n=7,
labels = c("0 to 15", ">15 to 20", ">20 to 25", ">25 to 30", ">30 to 35", ">35 to 40", ">40 to 45"))
但是,每次您為類別數設置不同的n
值時,您顯然都必須手動更改此設置。
無論地圖中如何使用類別,是否可以自動生成類似的輸出?
以下代碼從閉區間(即 >=)創建方括號,並為開區間(即 <)創建“簡單”括號。 這是一個合理的解決方案嗎? 您還可以在legend.format
參數中閱讀更多詳細信息。
library(tmap)
#> Warning: replacing previous import 'sf::st_make_valid' by
#> 'lwgeom::st_make_valid' when loading 'tmap'
data("World")
tm_shape(World) +
tm_polygons("HPI", n = 7, legend.format = list(scientific = TRUE, format = "f"))
由reprex 包(v0.3.0) 於 2020 年 3 月 3 日創建
我設法通過使用以下方法使其工作:
legend.format = list(format = "f", text.separator = "<"))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.