如何在地图上使用 ggplot borders()

how to use ggplot borders() with maps

我正在尝试在州界周围画一个白色边框。我不明白为什么下面的示例会引发错误,因为它似乎与文档一致。什么是正确的方法?谢谢

#http://docs.ggplot2.org/0.9.2.1/geom_map.html
crimes <- data.frame(state = tolower(rownames(USArrests)), USArrests)
library(reshape2) # for melt
crimesm <- melt(crimes, id = 1)
if (require(maps)) {
  states_map <- map_data("state")
  gg<-ggplot(crimes, aes(map_id = state))
  gg<-gg + geom_map(aes(fill = Murder), map = states_map) + expand_limits(x = states_map$long, y = states_map$lat)
  gg<- gg + coord_map()
  #works
  print(gg)
  #Now try to add a borders layer
  #throws "Error in eval(expr, envir, enclos) : object 'state' not found"
  print(gg+borders("state",colour="white"))
}

尝试

gg + borders("state", inherit.aes = F, colour = "white")