Map with Panels

I follow a great example here . Everything works up to the grid graph,

library("lattice")
spplot(sp_grd, "id", colorkey=FALSE,
       panel = function(...) {
         panel.gridplot(..., border="black", col.regions="white")
         sp.polygons(shp)
         sp.points(poi, cex=1.5)
         panel.text(..., col="red")
       })

When I try to do this, I get an error,

'Error when using package 1 formal argument "col.regions", matched by several actual arguments.

Any ideas for fixes? Basically, I do not want the panels to fill with colors, as it is by default.

EDIT: Reproducible example modified from a link.

### read shapefile
library("rgdal")
library("lattice")
library("rworldmap")
shp <- getMap(resolution="low")

### define coordinates and convert to SpatialPointsDataFrame
poi <- data.frame(x=c(15, 25, 35, 100),
                  y=c(-15, 25, -35, -50),
                  id="A", stringsAsFactors=F)
coordinates(poi) <- ~ x + y
proj4string(poi) <- proj4string(shp)

### define SpatialGrid object
bb <- bbox(shp)
cs <- c(10, 10)
cc <- bb[, 1] + (cs/2)  # cell offset
cd <- ceiling(diff(t(bb))/cs)  # number of cells per direction
grd <- GridTopology(cellcentre.offset=cc, cellsize=cs, cells.dim=cd)

sp_grd <- SpatialGridDataFrame(grd,
                               data=data.frame(id=1:prod(cd)),
                               proj4string=CRS(proj4string(shp)))
# does work
spplot(sp_grd, "id",
       panel = function(...) {
         panel.gridplot(..., border="black")
         sp.polygons(shp)
         sp.points(poi, cex=1.5)
         panel.text(...)
       })

# does not work
spplot(sp_grd, "id",
       panel = function(...) {
         panel.gridplot(..., border="black", col.regions="white")
         sp.polygons(shp)
         sp.points(poi, cex=1.5)
         panel.text(...)
       })
+4
source share
1 answer

, panel.gridplot() col.regions. , ( ) (...) .

, col.regions . , col.regions, (.. spplot()), , .... panel.gridplot() col.regions= , .

:

spplot(sp_grd, "id", colorkey=FALSE,
       panel = function(..., col.regions) {
         panel.gridplot(..., border="black", col.regions="white")
         sp.polygons(shp)
         sp.points(poi, cex=1.5)
         panel.text(...)
})
+4

Source: https://habr.com/ru/post/1620423/


All Articles