我试图在州界附近画一个白色边框。我无法弄清楚为什么下面的示例会抛出错误,因为它似乎与文档一致。什么是正确的方法?感谢。
#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"))
}
答案 0 :(得分:1)
Try
gg + borders("state", inherit.aes = F, colour = "white")