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")

