1

I want to plot my kriging-results which are stored in a SpatialPixelsDataFrame object. Using spplot, it automatically creates a plot including var1.pred, var1.var and var1.stdev.

This is nice, but I want the spplot function to only plot var1.pred, which is why I want to delete var1.var and var1.stdev (they are stored as attributes in the slot @data).

I don't know how to do this - can anybody help? Thanks in advance!

Let's say my object is called "aa", then here is the information about it:

str(aa)
Formal class 'SpatialPixelsDataFrame' [package "sp"] with 7 slots
 ..@ data       :'data.frame':  4986 obs. of  3 variables:
 .. ..$ var1.pred : num [1:4986] 5.95 5.96 5.96 5.94 5.95 ...
 .. ..$ var1.var  : num [1:4986] 0.000445 0.0005 0.00072 0.008354 0.000917 ...
 .. ..$ var1.stdev: num [1:4986] 0.0211 0.0224 0.0268 0.0914 0.0303 ...
 ..@ coords.nrs : int [1:2] 1 2
 ..@ grid       :Formal class 'GridTopology' [package "sp"] with 3 slots
 .. .. ..@ cellcentre.offset: Named num [1:2] 0.139 0.408
 .. .. .. ..- attr(*, "names")= chr [1:2] "x1" "x2"
 .. .. ..@ cellsize         : Named num [1:2] 0.174 0.174
 .. .. .. ..- attr(*, "names")= chr [1:2] "x1" "x2"
 .. .. ..@ cells.dim        : Named int [1:2] 56 154
 .. .. .. ..- attr(*, "names")= chr [1:2] "x1" "x2"
 ..@ grid.index : int [1:4986] 8604 8548 8492 8435 8436 8379 8380 8323 8324 8325 ...
 ..@ coords     : num [1:4986, 1:2] 6.22 6.22 6.22 6.05 6.22 ...
 .. ..- attr(*, "dimnames")=List of 2
 .. .. ..$ : NULL
 .. .. ..$ : chr [1:2] "x1" "x2"
 ..@ bbox       : num [1:2, 1:2] 0.139 0.408 9.697 26.994
 .. ..- attr(*, "dimnames")=List of 2
 .. .. ..$ : chr [1:2] "x1" "x2"
 .. .. ..$ : chr [1:2] "min" "max"
 ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slots
 .. .. ..@ projargs: chr NA

3 Answers3

1

Please next time provide a reproductible example and no need to delete something here.

In the help file of spplot you have

  spplot.grid(obj, zcol = names(obj), ..., names.attr, scales = list(draw = FALSE),
  xlab = NULL, ylab = NULL, aspect = mapasp(obj,xlim,ylim),
  panel = panel.gridplot, sp.layout = NULL, formula, xlim = bbox(obj)[1, ],
  ylim = bbox(obj)[2, ], checkEmptyRC = TRUE)

....................................................................
....................................................................
....................................................................

 obj: object of class extending Spatial-class

zcol: character; attribute name(s) or column number(s) in attribute
      table
....................................................................
....................................................................
....................................................................

When you get stuck in R, the first thing to try is the help file first. Here you could have seen that the zcol parameters can solve you problem.

Using the meuse.grid dataset which have 5 columns, we can decide to plot the "soil" column like this

require(sp)
data(meuse.grid) 
coordinates(meuse.grid) = c("x", "y") 
gridded(meuse.grid) <- TRUE

class(meuse.grid)
[1] "SpatialPixelsDataFrame"
attr(,"package")
[1] "sp"

names(meuse.grid)
[1] "part.a" "part.b" "dist"   "soil"   "ffreq" 

spplot(meuse.grid, "soil")

This one will work too

spplot(meuse.grid["soil"])
Community
  • 1
  • 1
dickoa
  • 18,217
  • 3
  • 36
  • 50
0

a@data is a data.frame, so you can maniplate it like a dataframe:

a@data<-a@data[,1,drop=FALSE]

The drop=FALSE parameter makes [] not try to reduce the result to the least dimensionality.

Dave X
  • 4,831
  • 4
  • 31
  • 42
0

Specify the plot name:

split(dataset["vari.pred"])
Tunaki
  • 132,869
  • 46
  • 340
  • 423