简体   繁体   English

在 R 中删除 tmap 中的图例

[英]Remove legend in tmap in R

I have a simple question: How does one remove an automatically added legend in tmap in R?我有一个简单的问题:如何在 R 中删除 tmap 中自动添加的图例?

In this case, I want to remove that legend on the right, depicting 'level'.在这种情况下,我想删除右侧的图例,描绘“级别”。

在此处输入图片说明

Here's what I've tried:这是我尝试过的:

tm_shape(densities$polygons)+
  tm_polygons(col='level', palette='Reds', alpha=0.5, border.col = 'transparent') + 
  tm_legend(show=FALSE)

I have also tried:我也试过:

tm_shape(densities$polygons)+
  tm_polygons(col='level', palette='Reds', alpha=0.5, border.col = 'transparent') + 
  tm_layout(legend.show=FALSE)

Not sure why but none of these removes the legend.不知道为什么,但这些都没有删除图例。 Would appreciate any solutions, thank you!希望有任何解决方案,谢谢!

Try this:尝试这个:

library(tmap)

tmap_mode("view")

tm_shape(densities$polygons) +
  tm_polygons(col = "plz", legend.show = FALSE) 

tm_layout() doesn't work in your case because you are in view -mode. tm_layout()在您的情况下不起作用,因为您处于view模式。 Several other options for the legend in view mode won't work with tm_layout either, such as legend.position = (there is tm_view() for this)视图模式下图例的其他几个选项也不适用于 tm_layout,例如legend.position =tm_view()tm_view()

If you switch to tmap_mode("plot") your code will work.如果您切换到tmap_mode("plot")您的代码将起作用。

Instead of tm_polygons use tm_fill(title = "") to remove the legend title.而不是tm_polygons使用tm_fill(title = "")删除图例标题。 This worked for me.这对我有用。

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

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