Get boundaries to come through on states

泪湿孤枕 提交于 2019-12-04 06:43:22

问题


Edit 7 :

After quite a bit of help, I've been able to get a map that is getting close to the results I need. But I still need to have the state boundaries come through on the map, but I can't figure it out. In order to make a reproducible example that would be appropriate I need to link to the data set since the dput is so large.

To make things easy, I subset only three states, but where the boundary lines do not show up. I would like to be able to have the boundary lines come through the plot as white lines, like they are on the rest of the map. Thanks for your help.

Dataset :

https://www.dropbox.com/s/0evuvrlm49ab9up/PRISM_1895_db.csv?dl=0

Rep Code :

PRISM_1895_db <- read.csv("PRISM_1895_db.csv")

regions<- c("north dakota","south dakota","nebraska","kansas","oklahoma","texas","minnesota","iowa","missouri","arkansas", "illinois", "indiana", "wisconsin")

ggplot() + 
  geom_polygon(data=subset(map_data("state"), region %in% regions), aes(x=long, y=lat, group=group), col="white") +
  geom_point(data = PRISM_1895_db2, aes(x = longitude, y = latitude, color = APPT), alpha = .5, size = 3.5) 

Graph :


回答1:


The order in which you draw the layers matters. If you want the while lines on top, you'll need to add them last. And if you want the black shapes in the background, you need them first. So basically you need to split up the states into two draws: the background and the outline.

ggplot() + 
  geom_polygon(data=subset(map_data("state"), region %in% regions), aes(x=long, y=lat, group=group)) +
  geom_point(data = PRISM_1895_db, aes(x = longitude, y = latitude, color = APPT), alpha = .5, size = 3.5) +
  geom_polygon(data=subset(map_data("state"), region %in% regions), aes(x=long, y=lat, group=group), color="white", fill=NA)

which produces



来源:https://stackoverflow.com/questions/27957378/get-boundaries-to-come-through-on-states

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!