stack                   package:sp                   R Documentation

_r_e_a_r_r_a_n_g_e _d_a_t_a _i_n _S_p_a_t_i_a_l_P_o_i_n_t_s_D_a_t_a_F_r_a_m_e _o_r _S_p_a_t_i_a_l_G_r_i_d_D_a_t_a_F_r_a_m_e 
_f_o_r _p_l_o_t_t_i_n_g _w_i_t_h _s_p_p_l_o_t (_l_e_v_e_l_p_l_o_t/_x_y_p_l_o_t _w_r_a_p_p_e_r)

_D_e_s_c_r_i_p_t_i_o_n:

     rearrange SpatialPointsDataFrame for plotting with spplot or
     levelplot

_U_s_a_g_e:

     map.to.lev(data, zcol = 1:n, n = 2, names.attr)
     stack.SpatialPointsDataFrame(x, select, ...)

_A_r_g_u_m_e_n_t_s:

    data: object of class (or extending) SpatialDataFrame 

    zcol: z-coordinate column name(s), or a column number (range)
          (after removing the spatial coordinate columns: 1 refers to
          the first non-coordinate column, etc. ) 

names.attr: names of the set of z-columns (these names will appear in
          the plot); if omitted, column names of 'zcol' 

       n: number of columns to be stacked 

       x: same as 'data'

  select: same as 'zcol'

     ...: ignored 

_V_a_l_u_e:

     'map.to.lev' returns a data frame with the following elements: 

       x: x-coordinate for each row

       y: y-coordinate for each row

       z: column vector with each of the elements in columns 'zcol' of
          'data' stacked 

    name: factor; name of each of the stacked 'z' columns 


     'stack' is an S3 method: it return a data.frame with a column
     'values' that has the stacked coordinates and attributes, and a
     column 'ind' that indicates the variable stacked; it also
     replicates the coordinates.

_S_e_e _A_l_s_o:

     spplot, levelplot in package 'lattice', and stack

_E_x_a_m_p_l_e_s:

     library(lattice)
     data(meuse.grid) # data frame
     coordinates(meuse.grid) = c("x", "y") # promotes to SpatialDataFrame
     meuse.grid[["idist"]] = 1 - meuse.grid[["dist"]] # add variable
     # the following is made much easier by spplot:
     levelplot(z~x+y|name, map.to.lev(meuse.grid, z=c("dist","idist"), names.attr =
             c("distance", "inverse of distance")), aspect = "iso")
     levelplot(values~x+y|ind, as.data.frame(stack(meuse.grid)),aspect = "iso")
     gridded(meuse.grid) = TRUE
     levelplot(z~x+y|name, map.to.lev(meuse.grid, z=c("dist","idist"), names.attr =
             c("distance", "inverse of distance")), aspect = "iso")
     levelplot(values~x+y|ind, as.data.frame(stack(meuse.grid)), asp = "iso")

