Please help the R newbie
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?
Thanks
Please help the R newbie
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?
Thanks
Step 1 - Download Uk PostalCode geographic information: For example http://www.doogal.co.uk/UKPostcodes.php
https://data.gov.uk/search?q=postcodes
http://www.freemaptools.com/download-uk-postcode-lat-lng.htm
You may choose the format of your choice. CSV is easy to work with. Import this table into R.
Step 2 - Create a Subset with your list
#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)
Step 3 - Create a spatial object and plot the map
#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')