繁体   English   中英

如何在地图上使用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") 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM