Skip to content

spplot help, please

4 messages · Marvin Sharma, Bede-Fazekas Ákos, Edzer Pebesma +1 more

#
Hi,I wanted to plot the spplot of my model residuals. The plot works fine, but the state map does not appear. Code is given below and the data are attached. I would greatly appreciate any help in this.
Marvin

library(spgwr)library(spdep)library(maps)library(maptools)data<-read.csv("try.csv",header=TRUE)coords=cbind(data$Longitude,data$Latitude)g.adapt.gauss <- gwr.sel(y~x, data,coords,adapt=TRUE)res.adpt <- gwr(y~x, data,coords, adapt=g.adapt.gauss)brks <- c(-0.25, 0, 0.01, 0.025, 0.075)cols <- grey(5:2/6)res.adpt$SDF$ols.e <- residuals(lm(y~x, data))spplot(res.adpt$SDF, c("ols.e","gwr.e"),main="Residuals")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20171021/39cd3667/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: try.csv
Type: application/vnd.ms-excel
Size: 8724 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20171021/39cd3667/attachment.xlb>
#
Hi Marvin,

this code works fine just as it should work. Which "state map" you need? 
A basemap with terrain/roads/cities/borders? In this case there are 
several possibilities to do that. Have a look at these links, they may 
solve your problem:
https://pakillo.github.io/R-GIS-tutorial/#gmap
http://www.nickeubank.com/wp-content/uploads/2015/10/RGIS3_MakingMaps_part1_mappingVectorData.html 
(Section "4.2 Basemaps with spplot")

HTH,
?kos Bede-Fazekas
Hungarian Academy of Sciences


2017.10.21. 3:29 keltez?ssel, Marvin Sharma via R-sig-Geo ?rta:

  
  
#
On 10/21/2017 03:29 AM, Marvin Sharma via R-sig-Geo wrote:
I can't see where you're trying to plot/add a state map, in the example
below.

  
    
#
The others are right, there is no state map in your code that you might 
add to the points plot.

After a quick inspection of which geographic area we are dealing with, 
here is one possible - and quite basic - solution on how to add state 
polygons of the US (if that is what you intend to do) to your plot:

## download state polygons for the us
library(raster)
usa = getData("GADM", country = "USA", level = 1)

## create subset of state polygons (otherwise spplot() will take quite 
long)
proj4string(res.adpt$SDF) = "+init=epsg:4326"

ext = extend(extent(res.adpt$SDF), 2.5)
states = crop(usa, ext)

## add state boundaries using 'sp.layout'
p = spplot(res.adpt$SDF, c("ols.e","gwr.e"), main = "Residuals",
 ?????????? sp.layout = list("sp.polygons", states))
p

Alternatively, you could also use latticeExtra::layer() instead of 
'sp.layout'. Simply have a look at the help pages for further details.

Cheers,
Florian


Am 21.10.2017 um 10:58 schrieb Edzer Pebesma: