Description Usage Arguments Details Value Examples

This function computes the deviation between regional ratios and local ratios. Local ratios are defined either by a contiguity order or by a distance measure between regions. Each elementary unit value will be compared to the value of its neighborhood.

1 2 |

`x` |
a data frame. |

`var1` |
name of the numerator variable in x. |

`var2` |
name of the denominator variable in x. |

`type` |
type of deviation; "rel" for relative deviation, "abs" for absolute deviation (see Details). |

`spdf` |
a SpatialPolygonsDataFrame that matches x data frame. |

`order` |
contiguity order. |

`dist` |
distance threshold defining the contiguity. The cartesian
distance between units centroids is used by default
(see |

`mat` |
a distance matrix (road distance, travel time...) between x units. Row and column names must fit xid identifiers. (optional) |

`spdfid` |
identifier field in spdf, default to the first column of the spdf data frame. (optional) |

`xid` |
identifier field in x, default to the first column of x. (optional) |

The relative spatial deviation is the ratio between var1/var2 and
var1/var2 in the specified neighborhoud. Values greater than 100 indicate
that the unit ratio is greater than the ratio in its neighborhoud. Values
lower than 100 indicate that the unit ratio is lower than the ratio in its
neighborhoud.

The absolute spatial deviation is the amount of numerator that could be
moved to obtain the same ratio in all units of its neighborhoud.

A vector is returned.

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 | ```
# load data
data("GrandParisMetropole")
# compute absolute spatial deviation in a neighborhood defined by a contiguity
# order of 2.
com$sdevabs <- sdev(x = com, var1 = "INC", var2 = "TH",
type = "abs", spdf = com.spdf, order = 2)
# compute relative spatial deviation in a neighborhood defined within a distance
# of 5km between communes' centroids
com$sdevrel <- sdev(x = com, var1 = "INC", var2 = "TH", type = "rel",
spdf = com.spdf, dist = 5000)
# compute absolute spatial deviation in a neighborhood defined within a road
# travel time of 10 minutes by car
com$scardevabs <- sdev(x = com, var1 = "INC", var2 = "TH", type = "abs",
spdf = com.spdf, dist = 10, mat = cardist)
# compute relative spatial deviation in a neighborhood defined within a road
# travel time of 10 minutes by car
com$scardevrel <- sdev(x = com, var1 = "INC", var2 = "TH", type = "rel",
spdf = com.spdf, dist = 10, mat = cardist)
# map deviations
if(require('cartography')){
library(sp)
# set graphical parameters
par(mar = c(0,0,1.2,0))
# set breaks
bks <- c(min(com$scardevrel),50,75,100,125,150,max(com$scardevrel))
bks <- sort(bks)
# set colot palette
cols <- carto.pal(pal1 = "blue.pal", n1 = 3,
pal2 = "wine.pal", n2 = 3)
# plot a choropleth map of the relative spatial deviation
choroLayer(spdf = com.spdf, df = com, var = "scardevrel",
legend.pos = "topleft",
legend.title.txt = "Relative Deviation",
breaks = bks, border = NA,
col = cols)
# add symbols proportional to the absolute spatial deviation
com$sign <- ifelse(test = com$scardevabs<0, yes = "negative", no = "positive")
propSymbolsTypoLayer(spdf = com.spdf, df = com, var = "scardevabs",var2 = "sign",
legend.var.pos = "left",legend.values.rnd = -2,
legend.var2.values.order = c("positive", "negative"),
legend.var.title.txt = "Absolute Deviation",
col = c("#ff000050","#0000ff50"),legend.var2.pos = "n",
legend.var.style = "e", inches = 0.2)
# add a layout
layoutLayer(title = "Spatial Deviation (neighborhoud: 10 minutes by car)",
sources = "GEOFLA® 2015 v2.1, impots.gouv.fr", north = TRUE,
author = "MTA")
}
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.