area.plot: Graphical Display of Areas

Description Usage Arguments Value Author(s) Examples

Description

'area' is a data frame with three variables.
The first variable is a factor defining the polygons.
The second and third variables are the xy coordinates of the polygon vertices in the order where they are found.

area.plot : grey levels areas mapping

poly2area takes an object of class 'polylist' (maptools package) and returns a data frame of type area.
area2poly takes an object of type 'area' and returns a list of class 'polylist'
area2link takes an object of type 'area' and returns a proximity matrix which terms are given by the length of the frontier between two polygons.
area.util.contour,area.util.xy and area.util.class are three utility functions.

Usage

1
2
3
4
5
6
7
8
9
area.plot(x, center = NULL, values = NULL, graph = NULL, lwdgraph = 2,
nclasslegend = 8, clegend = 0.75, sub = "", csub = 1, 
possub = "topleft", cpoint = 0, label = NULL, clabel = 0, ...)

area2poly(area)
poly2area(polys)
area2link(area)
area.util.contour(area)
area.util.xy(area)

Arguments

x

a data frame with three variables

center

a matrix with the same row number as x and two columns, the coordinates of polygone centers. If NULL, it is computed with area.util.xy

values

if not NULL, a vector which values will be mapped to grey levels. The values must be in the same order as the values in unique(x.area[,1])

graph

if not NULL, graph is a neighbouring graph (object of class "neig") between polygons

lwdgraph

a line width to draw the neighbouring graph

nclasslegend

if value not NULL, a number of classes for the legend

clegend

if not NULL, a character size for the legend, used with par("cex")*clegend

sub

a string of characters to be inserted as sub-title

csub

a character size for the sub-titles, used with par("cex")*csub

possub

a string of characters indicating the sub-titles position ("topleft", "topright", "bottomleft", "bottomright")

cpoint

if positive, a character size for drawing the polygons vertices (check up), used with par("cex")*cpoint

label

if not NULL, by default the levels of the factor that define the polygons are used as labels. To change this value, use label. These labels must be in the same order than unique(x.area[,1])

clabel

if not NULL, a character size for the polygon labels,
used with par("cex")*clabel

polys

a list belonging to the 'polylist' class in the spdep package

area

a data frame of class 'area'

...

further arguments passed to or from other methods

Value

poly2area returns a data frame 'factor,x,y'.
area2poly returns a list of class polylist.

Author(s)

Daniel Chessel

Examples

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
data(elec88)
par(mfrow = c(2, 2))
area.plot(elec88$area, cpoint = 1)
area.plot(elec88$area, lab = elec88$lab$dep, clab = 0.75)
area.plot(elec88$area, clab = 0.75)
# elec88$neig <- neig(area = elec88$area)
area.plot(elec88$area, graph = elec88$neig, sub = "Neighbourhood graph", possub = "topright")
par(mfrow = c(1, 1))

## Not run: 
    par(mfrow = c(3, 3))
    for(i in 1:9) {
      x <- elec88$tab[,i]
      area.plot(elec88$area, val = x, sub = names(elec88$tab)[i], csub = 3, cleg = 1.5)
    }
    par(mfrow = c(1, 1))
    
    if(adegraphicsLoaded()) {
      if(requireNamespace("sp", quiet = TRUE)) {
        s.value(elec88$xy, elec88$tab, Sp = elec88$Spatial,
          meth = "color", psub.text = names(elec88$tab), psub.cex = 3, 
          pSp.col = "white", pgrid.draw = F, porigin.incl = FALSE)
      }
    } else {
      par(mfrow = c(3, 3))
      for(i in 1:9) {
        x <- elec88$tab[, i]
        s.value(elec88$xy, elec88$tab[, i], contour = elec88$contour,
         meth = "greylevel", sub = names(elec88$tab)[i], csub = 3, 
         cleg = 1.5, incl = FALSE)
        }
      par(mfrow = c(1, 1))
    }
    
    if(!adegraphicsLoaded()) {
      data(irishdata)
      par(mfrow = c(2, 2))
      w <- ade4:::area.util.contour(irishdata$area)
      xy <- ade4:::area.util.xy(irishdata$area)
      area.plot(irishdata$area, cpoint = 1)
      apply(w, 1, function(x) segments(x[1], x[2], x[3], x[4], lwd = 3))
      area.plot(irishdata$area, clabel = 1)
      s.label(xy, area = irishdata$area, incl = FALSE, clab = 0, 
        cpoi = 3, addax = FALSE, contour = w)
      s.label(xy, area = irishdata$area, incl = FALSE, 
        addax = FALSE, contour = w)
      if(requireNamespace("maptools", quiet = TRUE) & requireNamespace("spdep", quiet = TRUE)) {
        data(columbus)
        par(mfrow = c(2, 2))
        plot(col.gal.nb, coords, pch = 20, cex = 2)
        col.gal.neig <- nb2neig(col.gal.nb)
        s.label(data.frame(coords), neig = col.gal.neig,
          inc = FALSE, addax = FALSE, clab = 0, cneig = 1, cpo = 2)
        maptools:::plot.polylist(polys, bbs)
        area.plot(poly2area(polys))
    
        # 1
        crime.f <- as.ordered(cut(columbus$CRIME,
          breaks = quantile(columbus$CRIME, probs = seq(0, 1, 0.2)),
          include.lowest = TRUE))
        colours <- c("salmon1", "salmon2", "red3", "brown", "black")
        plot(bbs[, 1], bbs[, 4], xlab = "", ylab = "", asp = 1, type = "n",
          xlim = range(c(bbs[, 1], bbs[, 3])), ylim = range(c(bbs[, 2],
          bbs[, 4])))
        for(i in 1:length(polys)) 
          polygon(polys[[i]], col = colours[unclass(crime.f[i])])
          legend(x = c(6, 7.75), y = c(13.5, 15), legend = levels(crime.f),
          fill = colours, cex = 0.7)
        title(sub = paste("Columbus OH: residential burglaries and ",
          "vehicle\nthefts", "per thousand households, 1980"))
        
        # 2
        area1 <- poly2area(polys)
        w <- ade4:::area.util.contour(area1)
        wxy <- ade4:::area.util.xy(area1)
        area.plot(area1, values = columbus$CRIME, sub = paste("Columbus ",
          "OH: residential burglaries and vehicle\nthefts",
          "per thousand households, 1980"))
        apply(w, 1, function(x) segments(x[1], x[2], x[3], x[4], lwd = 2))
    
        # 3
        data(elec88)
        fr.area <- elec88$area
        fr.xy <- ade4:::area.util.xy(fr.area)
        fr.neig <- elec88$neig # neig(area = fr.area)
    
        # 4
        fr.poly <- area2poly(fr.area)
        fr.nb <- neig2nb(fr.neig)
        maptools:::plot.polylist(fr.poly, attr(fr.poly, "region.rect"), border = "grey")
        plot(fr.nb, fr.xy, add = TRUE)
        s.label(fr.xy, clab = 0, area = fr.area, neig = fr.neig, 
          cneig = 1, cpo = 2, inc = FALSE, addax = FALSE)
        par(mfrow = c(1, 1))
      }
      par(mfrow = c(1, 1))
    }

## End(Not run)

data(irishdata)
w <- irishdata$area[c(42:53, 18:25), ]
w
w$poly <- as.factor(as.character(w$poly))
area.plot(w, clab = 2)
 
points(68, 59, pch = 20, col = "red", cex = 3)
points(68, 35, pch = 20, col = "red", cex = 3)
points(45, 12, pch = 20, col = "red", cex = 3)
sqrt((59 - 35) ^ 2) + sqrt((68 - 45) ^ 2 + (35 - 12) ^ 2)
area2link(w)

Example output

Loading required namespace: maptools
Failed with error:  'unused argument (quiet = TRUE)'
Loading required namespace: spdep
Failed with error:  'unused argument (quiet = TRUE)'
   poly   x  y
42  S07  16 50
43  S07  16 44
44  S07  44 47
45  S07  21 34
46  S07  20 20
47  S07  28 19
48  S07  46 23
49  S07  30  8
50  S07  45 12
51  S07  68 35
52  S07  68 59
53  S07  63 78
18  S04  68 35
19  S04  68 59
20  S04 112 55
21  S04 119 50
22  S04 132 25
23  S04  74  0
24  S04  45  0
25  S04  45 12
[1] 56.52691
         S07      S04
S07  0.00000 56.52691
S04 56.52691  0.00000

ade4 documentation built on May 2, 2019, 5:50 p.m.

Related to area.plot in ade4...