在R中的地图上绘制英国邮政编码 [英] Plotting UK postcodes on a map in R
本文介绍了在R中的地图上绘制英国邮政编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请帮助R新手
我有一个英国邮政编码列表-实际上有300万个观测值.使用R将它们绘制到地图上的最佳方法是什么?
I have a list of UK postcodes - 3m observations in fact. What is the best way of plotting them on to a map using R?
谢谢
推荐答案
步骤1-下载英国邮政编码地理信息:例如 http://www.doogal.co.uk/UKPostcodes.php
https://data.gov.uk/search?q=postcodes
http://www.freemaptools.com/download-uk -postcode-lat-lng.htm
您可以选择所需的格式. CSV易于使用. 将此表导入R.
You may choose the format of your choice. CSV is easy to work with. Import this table into R.
第2步-使用您的列表创建子集
#You have now a data.frame Df_UK containing geoinfo.
#Your initial list is in Df_JVT with variable PostCodes.
list <- as.list(unique(Df_JVT$PostCodes))
#Select your postcodes from Df_UK and choose variable to display on the map
datamap <- subset(Df_UK, Df_UK$POSTNR %in% list, select= c("POSTNR","CITY", "COUNTY", "LAT", "LON"))
row.names(datamap) <- 1:nrow(datamap)
第3步-创建空间对象并绘制地图
#Transform data.frame in spatial object
require(rgdal)
require(sp)
require(plotGoogleMaps)
datamap_mat<- cbind(datamap$LON,datamap$LAT)
row.names(datamap_mat) <- 1:nrow(datamap_mat)
AACRS <- CRS("+proj=longlat +ellps=WGS84")
UK_Map <- SpatialPointsDataFrame(datamap_mat, datamap, proj4string = AACRS, match.ID = TRUE)
#Map Points on Googlemaps
m <- plotGoogleMaps(UK_Map , filename='MAP_UK.html')
这篇关于在R中的地图上绘制英国邮政编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文