通过状态获取边界 [英] Get boundaries to come through on states

查看:153
本文介绍了通过状态获取边界的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑7:

经过相当多的帮助,我已经能够获得一张接近我需要的结果的地图。但我仍然需要在地图上通过州界,但我无法弄清楚。为了创建一个适合的可重复的例子,我需要链接到数据集,因为dput是如此之大。

为了让事情变得简单,我只将子集分为三个状态,但边界线没有出现。我希望能够让边界线以白线的形式出现,就像他们在地图的其他部分一样。感谢您的帮助。

数据集:

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



代码:

  PRISM_1895_db<  -  read.csv(PRISM_1895_db.csv ),南达科他州,内布拉斯加州,堪萨斯州,俄克拉荷马州,德克萨斯州,明尼苏达州,爱荷华州,密苏里州,阿肯色州,伊利诺伊州,印第安纳州,威斯康星州)

ggplot()+
geom_polygon(data = subset(map_data(state 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)

图:

解决方案

您绘制的顺序层次很重要。如果你想让最上面的那一行显示,你需要最后添加它们。如果你想要在背景中的黑色形状,你首先需要他们。所以基本上你需要将州分成两个画:背景和大纲。

  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 y =纬度,颜色= 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)

它产生




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 :

解决方案

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

这篇关于通过状态获取边界的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆