简体   繁体   中英

how to use ggplot borders() with maps

I am trying to draw a white border around state boundaries. I can't figure out why the example below throws an error as it seems to be consistent with the documentation. What is the right way? Thanks.

#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") 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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