I am having troubles with adding fixed breaks to a tm_map. I tried the same code as another topic at this forum (Customize how R tmap legend values are printed) on a different dataset, but the principle is the same. I used the example from the forum because adding all the values in the breaks-section in the line of Map1 also didn't work. However, both situations gave me the error:
Error in .subset2(x, i, exact = exact) : no such index at level 1
Could anybody explains me what this error exactly means and how to overcome it?
code
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
question from:
https://stackoverflow.com/questions/65626671/issue-with-adding-breaks-to-a-tm-object 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…