[R-sig-Geo] Half degree gridded data using rworldmap library - SpatialPixelsDataFrame

Nerijus Uza nerijusuza at yahoo.com
Tue Jun 23 20:47:39 CEST 2015


Hello,
I'm very new when it comes to R. I recently started looking into geographical data and mapping. I was using this pdf (and many more) as an example for my analysis. It's pretty straight forward if I want a country map (country map code)
|   |
|   |  |   |   |   |   |   |
| country map.txtShared with Dropbox |
|  |
| View on www.dropbox.com | Preview by Yahoo |
|  |
|   |



Half degree gridded data map is what I'm really interested in. I limited my source to coordinates in Unites States only. I need SpatialGridDataFrame to plot the map. Unfortunately, I can't get it to work. I get an error: > pixelDF <- pointsDF
> gridded(pixelDF) <- TRUE  #fullgrid
suggested tolerance minimum: 8.72547e-06 Error in points2grid(points, tolerance, round) : dimension 1 : coordinate intervals are not constant

Is the code correct? Are there any other methods to convert source data to SpatialGridDataFrame? Source can be found here.
# Librarylibrary(rworldmap)library(sp)library(RColorBrewer)
# Read source data filerdf <- read.csv("sample.csv", header = T, sep = ",")colnames(rdf) <- c("Latitude", "Longitude", "Count")
# promote to SpatialPointsDataFrame pointsDF <- rdf coordinates(pointsDF) = c("Latitude", "Longitude")
# promote to SpatialPixelsDataFramepixelDF <- pointsDF gridded(pixelDF) <- TRUE  #fullgrid
# promote to SpatialGridDataFramesGDF = as(pixelDF, "SpatialGridDataFrame")
# set plot marginspar(mai=c(0,0,0.2,0),xaxs="i",yaxs="i")
# set scalenumCats <- 9
# set colorcolourPalette <- brewer.pal(numCats, "YlOrRd")
# plot the map using rworldmap mapParams <- mapGriddedData(sGDF, nameColumnToPlot = "Count", colourPalette=colourPalette, numCats=numCats, addLegend = "FALSE")
# call legenddo.call( addMapLegend, c( mapParams, legendLabels="all", legendWidth=0.5, legendMar = 2))

I appreciate your help.
Regards,Nerijus
 
	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list