Debian Codegraph @

man/stack.Rd

raw
1 \name{stack}
2 \alias{spmap.to.lev}
3 \alias{stack.SpatialPointsDataFrame}
4 \alias{stack.SpatialGridDataFrame}
5 \title{ rearrange data in SpatialPointsDataFrame or SpatialGridDataFrame
6 for plotting with spplot (levelplot/xyplot wrapper) }
7 \description{
8 rearrange SpatialPointsDataFrame for plotting with spplot or levelplot }
9 \usage{
10 spmap.to.lev(data, zcol = 1:n, n = 2, names.attr)
11 \method{stack}{SpatialPointsDataFrame}(x, select, ...)
12 \method{stack}{SpatialGridDataFrame}(x, select, ...)
13 }
14 \arguments{
15 \item{data}{ object of class (or extending) SpatialPointsDataFrame or
16 SpatialGridDataFrame }
17 \item{zcol}{ z-coordinate column name(s), or a column number (range) (after
18 removing the spatial coordinate columns: 1 refers to the first non-coordinate
19 column, etc. ) }
20 \item{names.attr}{names of the set of z-columns (these names
21 will appear in the plot); if omitted, column names of \code{zcol} }
22 \item{n}{ number of columns to be stacked }
23 \item{x}{ same as \code{data}}
24 \item{select}{ same as \code{zcol}}
25 \item{...}{ ignored }
26 }
27
28 \value{
29 \code{spmap.to.lev} returns a data frame with the following elements:
30 \item{x}{ x-coordinate for each row}
31 \item{y}{ y-coordinate for each row}
32 \item{z}{ column vector with each of the elements in columns \code{zcol}
33 of \code{data} stacked }
34 \item{name}{ factor; name of each of the stacked \code{z} columns }
35
36 \code{stack} is an S3 method: it return a data.frame with a column
37 \code{values} that has the stacked coordinates and attributes, and a
38 column \code{ind} that indicates the variable stacked; it also
39 replicates the coordinates. }
40
41 \seealso{ \link{spplot}, \link[lattice]{levelplot}, and \link{stack}}
42 \examples{
43 library(lattice)
44 data(meuse.grid) # data frame
45 coordinates(meuse.grid) = c("x", "y") # promotes to SpatialPointsDataFrame
46 meuse.grid[["idist"]] = 1 - meuse.grid[["dist"]] # add variable
47 # the following is made much easier by spplot:
48 levelplot(z~x+y|name, spmap.to.lev(meuse.grid, z=c("dist","idist"), names.attr =
49 c("distance", "inverse of distance")), aspect = "iso")
50 levelplot(values~x+y|ind, as.data.frame(stack(meuse.grid)),aspect = "iso")
51 gridded(meuse.grid) = TRUE
52 levelplot(z~x+y|name, spmap.to.lev(meuse.grid, z=c("dist","idist"), names.attr =
53 c("distance", "inverse of distance")), aspect = "iso")
54 levelplot(values~x+y|ind, as.data.frame(stack(meuse.grid)), asp = "iso")
55
56 }
57 \keyword{dplot}