首页 > 解决方案 > 向 tm_object 添加中断的问题

问题描述

我在向 tm_map 添加固定中断时遇到了麻烦。我在不同的数据集上尝试了与该论坛上另一个主题相同的代码(自定义如何打印 R tmap 图例值),但原理是相同的。我使用了论坛中的示例,因为在 Map1 行的休息部分中添加所有值也不起作用。然而,这两种情况都给了我错误: Error in .subset2(x, i, exact = exact) : no such index at level 1 谁能解释我这个错误的确切含义以及如何克服它?

代码

mybreaks1 = c(0, 5, 15, 25, 35, 70) 
mybreaks2 = c()

for (i in 1:length(mybreaks1)-1){
  print(i)
  if (i == 1){
    mybreaks2[i] <- paste0(mybreaks1[i], " - ", mybreaks1[i+1])
  }
  if (i >1){
    mybreaks2[i] <- paste0(prettyNum(mybreaks1[i]+1, big.mark = " "), " - ", prettyNum(mybreaks1[i+1], big.mark = " "))
  }
}
Map1 = tm_shape(Week1_PlasticMap) + tm_fill(col = "total.per.segment" , breaks = mybreaks1, labels = mybreaks2, style = "fixed", convert2density = TRUE, area = Week1_PlasticMap$area, title = "Plastics (m^-2)", interactive = TRUE) + tm_borders(col = "darkslategrey") + tm_layout(main.title = "Week 1", legend.outside = TRUE, attr.outside= TRUE, attr.outside.position=c("right", "bottom"), legend.width = 0.2, legend.height = 0.3)``` 


The dataframe Week1_Plastic can be downloaded via the link below, because the dimensions are to large to upload in this question.

https://www.transfernow.net/7il18A012021

标签: rmapstm

解决方案


我自己修好了!原来我的数据表有问题。


推荐阅读