`[.data.frame`(attr ,, region)出错:选择了未定义的列(R)

时间:2018-06-09 20:34:04

标签: r ggplot2 fortify

Quero usar o fortify没有seguintecódigo例子:

Brasil <- fortify(BRmap, region = "BRmap@data$GID_2") %>%  
mutate(id = as.integer(id)) %>%
full_join(BRmap@data, by =c("id" = "BRmap@data$GID_2")) %>%
select(c(id, long, lat, order, hole, piece, group, NAME_2))

BRmapéumfileshape retirado do site https://gadm.org

1 个答案:

答案 0 :(得分:0)

也许试试这个?

  • 请勿使用全名“BRmap @ data $ GID_2”。只需使用列名“GID_2”。
  • by参数需要一个字符/列表,而不是整数,因此mutate应该是mutate(id = as.character(id))
Brasil <- fortify(BRmap, region = "GID_2") %>%  
  mutate(id = as.character(id)) %>%
  full_join(BRmap@data, by =c("id" = "GID_2")) %>%
  select(c(id, long, lat, order, hole, piece, group, NAME_2))