简体   繁体   English

如何使用 tmap 更改图例文本

[英]How to change a legend text with tmap

I am trying to make a simple map with R and tmap, everything works well but I can't fully customize the legend.我正在尝试使用 R 和 tmap 制作一个简单的 map,一切正常,但我无法完全自定义图例。 I have used legend.format = list(text.separator = "-") to change the text from, say "40 to 60" to "40 - 60" (i want my map legend in french so i had to drop the "to").我已经使用legend.format = list(text.separator = "-")将文本从“40 到 60”更改为“40 - 60”(我想要我的 map 法文图例,所以我不得不放弃“至”)。 How can I fully customize it to display, say "De 40 à 80 k€" instead of "40 - 60"?.如何完全自定义它以显示,说“De 40 à 80 k€”而不是“40 - 60”? Here is my code:这是我的代码:

         tm_fill("EBE", title = "EBE (k€)", style = "fixed",
          breaks = c(40,60,80,100,110))+
          tm_borders() +
          tm_layout("EBE moyen par région",
            legend.title.size = 1,
            legend.text.size = 0.6,
            legend.position = c("left","bottom"),
            legend.format = list(text.separator = "-"),
            #legend.bg.color = "white",
            legend.bg.alpha = 1)

Here is my map:这是我的 map:

EBE par région EBE 地区

Thanks in advance.提前致谢。

Looks like you might be able to use the tm_add_legend https://rdrr.io/cran/tmap/man/tm_add_legend.html看起来你可以使用 tm_add_legend https://rdrr.io/cran/tmap/man/tm_add_legend.html

I used the below code to change the labels on one of my plots where I need 'Missing' (automatic tmap label) to be changed to '0'.我使用下面的代码更改了我需要将“缺失”(自动 tmap 标签)更改为“0”的地块上的标签。

tm_add_legend(type = "fill", 
    labels = c("0", "1 to 20", "21 to 40", "41 to 60", "61 to 80", "81 to 100"),
    col = c("grey", "#ffffd4", "#fed98e", "#fe9929", "#d95f0e", "#993404"),
    border.lwd = 0.5,
    title = "Count")

By the way, if you want to create more white space around the plot so that the title and legend dont overlap the actual map then you can use:顺便说一句,如果您想在 plot 周围创建更多空白区域,以便标题和图例不会与实际 map 重叠,那么您可以使用:

tm_layout(inner.margins = c(value,value,value,value)

(the 4 values are the for the bottom, left, top and right space) (这4个值是底部,左侧,顶部和右侧空间)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM