dotsInPolys             package:maptools             R Documentation

_P_u_t _d_o_t_s _i_n _p_o_l_y_g_o_n_s

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

     Make point coordinates for a dot density map

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

     dotsInPolys(pl, x, f = "random", offset, compatible = FALSE)

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

      pl: list of polygons of class 'polylist', or an object of class
          SpatialPolygons or SpatialPolygonsDataFrame

       x: integer vector of counts of same length as pl for dots

       f: type of sampling used to place points in polygons, either
          "random" or "regular"

  offset: for regular sampling only: the offset (position) of the
          regular grid; if not set, 'c(0.5,0.5)', that is the returned
          grid is not random

compatible: what to return, if TRUE a a list of matrices of point
          coordinates, one matrix for each member of pl, if false a
          SpatialPointsDataFrame with polygon ID values

_D_e_t_a_i_l_s:

     With f="random", the dots are placed in the polygon at random,
     f="regular" - in a grid pattern (number of dots not guaranteed to
     be the same as the count). When the polygon is made up of more
     than one part, the dots will be placed in proportion to the
     relative areas of the clockwise rings (anticlockwise are taken as
     holes). From maptools release 0.5-2, correction is made for holes
     in the placing of the dots, but depends on hole values being
     correctly set, which they often are not. The wrapper package spgpc
     may be used to check holes, see the 'dontrun' section of the
     example.

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

     If compatible=TRUE, the function returns a list of matrices of
     point coordinates, one matrix for each member of pl. If x[i] is
     zero, the list element is NULL, and can be tested when plotting -
     see the examples. If compatible=FALSE (default), it returns a
     SpatialPointsDataFrame with polygon ID values as the only column
     in the data slot.

_N_o_t_e:

     Waller and Gotway (2004) Applied Spatial Statistics for Public
     Health Data (Wiley, Hoboken, NJ) explicitly warn that care is
     needed in plotting and interpreting dot density maps (pp. 81-83)

_A_u_t_h_o_r(_s):

     Roger Bivand Roger.Bivand@nhh.no

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

     'spsample'

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

     x <- read.shape(system.file("shapes/sids.shp", package="maptools")[1])
     ncpolys <- Map2poly(x)
     try1 <- dotsInPolys(ncpolys, as.integer(x$att.data$SID74), compatible=TRUE)
     plot(ncpolys)
     xx <- lapply(try1, function(x) {if (!is.null(x)) points(as.matrix(rbind(x)),
      pch=18, col="red")}) # added as.matrix(rbind(x)), thanks to Nicholas Grassly
     try2 <- dotsInPolys(ncpolys, as.integer(x$att.data$SID74), f="regular", compatible=TRUE)
     plot(ncpolys)
     xx <- lapply(try2, function(x) {if (!is.null(x)) points(as.matrix(rbind(x)),
      pch=18, col="red")})
     nc_SP <- readShapePoly(system.file("shapes/sids.shp", package="maptools")[1],
      proj4string=CRS("+proj=longlat  +ellps=clrk66"))
     ## Not run: 
     library(spgpc)
     pls <- slot(nc_SP, "polygons")
     pls_new <- lapply(pls, checkPolygonsHoles)
     nc_SP <- SpatialPolygonsDataFrame(SpatialPolygons(pls_new,
      proj4string=CRS(proj4string(nc_SP))), data=as(nc_SP, "data.frame"))
     ## End(Not run)
     try1 <- dotsInPolys(nc_SP, as.integer(nc_SP$SID74))
     plot(nc_SP, axes=TRUE)
     plot(try1, add=TRUE, pch=18, col="red")
     try2 <- dotsInPolys(nc_SP, as.integer(nc_SP$SID74), f="regular")
     plot(nc_SP, axes=TRUE)
     plot(try2, add=TRUE, pch=18, col="red")

