在R中的tmap中删除图例 [英] Remove legend in tmap in R

查看:605
本文介绍了在R中的tmap中删除图例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的问题:如何删除R中tmap中自动添加的图例?

I have a simple question: How does one remove an automatically added legend in tmap in R?

在这种情况下,我想删除右侧的图例,描述等级".

In this case, I want to remove that legend on the right, depicting 'level'.

这是我尝试过的:

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

我也尝试过:

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!

推荐答案

尝试一下:

library(tmap)

tmap_mode("view")

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

tm_layout()在您的情况下不起作用,因为您处于view模式.在视图模式下,图例的其他几个选项也不能与tm_layout一起使用,例如legend.position =(为此有tm_view())

tm_layout() doesn't work in your case because you are in view-mode. 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)

如果您切换到tmap_mode("plot"),您的代码将可用.

If you switch to tmap_mode("plot") your code will work.

这篇关于在R中的tmap中删除图例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆