简体   繁体   English

如何更改 tm_bubble ( Tmap ) 的图例

[英]How to change legend of tm_bubble ( Tmap)

I created a map that has only has a value of 1 in the column "labour".我创建了一个 map,它在“劳动”列中的值为 1。 The issue I am getting is that the legend shows up as in 0.2 scale.我遇到的问题是图例显示为 0.2 比例。 How do I make sure only the one bubble (1.0 bubble) shows up in the legends but as the smallest size in the range?我如何确保只有一个气泡(1.0 气泡)出现在图例中,但作为范围内的最小尺寸?

在此处输入图像描述

this is the code I used这是我使用的代码

library(tmap)
tmap_mode("plot")
v11<-tm_shape(GEWEsettingmap)+
  tm_polygons("Construction", palette= "Reds",
              colorNA="white",
              showNA=FALSE)+
  tm_shape(GEWEsettingmap)+
  tm_bubbles(size="Labour",col="blue")+
  tm_shape(GEWEsettingmap)+
  tm_bubbles(size="Capital",col="yellow")+
  tm_shape(worldmap2) +
  tm_borders(col = "grey",lwd = 0.5)+
  tm_layout(bg.color = "white")+
  tm_layout(frame = TRUE,outer.margins=c(.05,0,.05,0), inner.margins=c(0,0,.02,0), asp=0,
            legend.outside=TRUE,
            legend.position=c("right","bottom"),
            title.position = c('right','top'))
#            legend.stack = "horizontal")
v11

I replaced the tm_bubble of labour in hopes to get what I wanted but I got an error:我更换了 tm_bubble of labor 希望得到我想要的但是我得到了一个错误:

  tm_bubbles(size="Capital",col="yellow",
             style="fixed",
             breaks=c(1),
             labels(1))
Error: symbol shape(s) ('shape' argument) is/are neither numeric nor valid variable name(s)

In your second code block, you didn't name the labels argument but used a labels() function instead, which was passed on to the next argument in the list, shape (the argument used to define what symbol is used to mark a point).在你的第二个代码块中,你没有命名labels参数,而是使用了labels() function ,它被传递给列表中的下一个参数, shape (用于定义用于标记点的符号的参数).

The first thing to do would be to try with the proper argument name:首先要做的是尝试使用正确的参数名称:

tm_bubbles(size = "Capital", col = "yellow",
             style = "fixed",
             breaks = 1,
             labels = 1)

However, to work with tm_bubbles() , I believe you should use the arguments sizes.legend (and sizes.legend.labels if at all needed) for customizing it.但是,要使用tm_bubbles() ,我相信您应该使用 arguments sizes.legend (和sizes.legend.labels如果需要的话)来定制它。 For example:例如:

tm_bubbles(size = "labour", col = "yellow",
             style = "fixed",
             sizes.legend = 1)

This would only show the bubble size for 1, and label it with "1".这只会显示 1 的气泡大小,而 label 则显示为“1”。 You can also make it automatically use all the unique values present in the dataset by using something like unique(GEWEsettingmap$Capital) .您还可以通过使用unique(GEWEsettingmap$Capital)类的内容使其自动使用数据集中存在的所有唯一值。

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

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