给定美国邮政编码,我如何在R中映射(在地理地图上)数据 [英] how do I map (on a geographical map) data in R just given the US Zipcodes

查看:143
本文介绍了给定美国邮政编码,我如何在R中映射(在地理地图上)数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于一个学校项目,我必须将一些数据映射到R中的地理地图上.因此,我得到了一些包含邮政编码和许多其他信息的数据(仅没有关于州,县或其他地方的更多信息). 我一直试图首先在美国的地图上指出我拥有的所有拉链.只是点.之后,我想混合和匹配数据中包含的zip数量之类的标准(例如,经常出现的zip我想将颜色涂成深色,将不常见的zips颜色涂成较浅的颜色,后来我想指出例如一个州的客户流失数量). 有人可以帮我解决这个问题吗?

for a school project I have to map some data on a geographical map in R. Therefore I've got some data containing the zipcode and many other information (just no more information on the state, county or whatever). I've been trying to point out on a map of the usa first all the zips I have. Just dots. Afterwards I wanted to mix and match the criteria like the count of zips I have in the data (e.g. the zips that appear very often I wanted to colour dark and the less often ones in a lither colour, later I wanted to point out e.g. the number of churns in a state). Can somebody help me out on how I can do this?

非常感谢

推荐答案

看看 R邮政编码包;该网站包含一些示例.该程序包具有所有邮政编码的地理坐标,因此在地图上显示它们会很简单.

Take a look at the R zipcode package; the website contains some examples. The package features geographical coordinates of all zipcodes, so it will be trivial to show them on a map.

这里是正确方向的另一个指针:安装软件包"maps"和"zipcode".将它们都加载到您的环境中:

Here is another pointer into the right direction: install the package "maps" and "zipcode". Load both of them into your environment:

library( zipcode ) ; library( maps )

现在绘制美国地图:

map( "usa" )

加载邮政编码数据

data( "zipcode" )

说,您有一些邮政编码,例如90001、46243、32920,并希望在地图上显示它们.

Say, you have some zipcodes, for example 90001, 46243, 32920 and you want to show them on the map.

selected <- zipcode[ zipcode$zip %in% c( "90001", "46243", "32920" ), ]

所选数据框包含有关邮政编码的信息.绘制它们.

The selected data frame contain information about the zipcodes. Plot them.

points( selected$longitude, selected$latitude, pch= 19, cex= 2 )
text( selected$longitude, selected$latitude, selected$zip, pos=3, cex= 2 )

这是结果:

这篇关于给定美国邮政编码,我如何在R中映射(在地理地图上)数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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