Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
177 views
in Technique[技术] by (71.8m points)

r - Issue with adding breaks to a tm_object

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I fixed it myself! Turned out that there was something wrong in my datasheet.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...