如何使用tmap包中的qtm()更改图例位置

时间:2017-12-12 15:15:56

标签: r plot maps tmap

我创建了一张显示犯罪数字的伦敦地图。正如你从下面的图片中看到的那样 - 我的传奇处于一个尴尬的地方 - 我更喜欢它在左下角还是右下角?任何人都知道我怎么可能这样做。我创建地图的代码如下。

另外,我如何为地图创建标题 - 我已经创建了图例标题。

地图和图例

enter image description here

qtm(brgh, fill = "Theft15", fill.title="Number of recorded thefts")

1 个答案:

答案 0 :(得分:2)

由于我没有您的数据,我决定使用tmap包中的数据进行以下演示。关键是使用tm_legend()。如果您查看当前的CRAN手册,可以在tm_layout()部分中找到更多信息。您可以使用legend.position中的tm_legend()指定图例的位置。对于主标题,您可以在函数中使用main.titlemain.title.position

library(tmap)

data(World, rivers, metro)

qtm(shp = World, fill = "economy", format = "World", style = "col_blind") +
tm_legend(legend.position = c("left", "top"),
          main.title = "My title",
          main.title.position = "right")

enter image description here

qtm(shp = World, fill = "economy", format = "World", style = "col_blind") +
tm_legend(legend.position = c("left", "bottom"),
          main.title = "My title",
          main.title.position = "right")

enter image description here