Learn R Programming

MTA (version 0.2.0)

gdev: General Deviation

Description

Compute the deviation of each territorial unit as regards to all the study area (or a reference value).

Usage

gdev(x, var1, var2, type = "rel", ref)

Arguments

x

a data.frame, an sf object or a SpatialPolygonsDataFrame, including var1 and var2.

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

ref

ratio of reference; if missing, the ratio of reference is the one of the whole study area (sum(var1) / sum(var2)).

Value

A vector is returned.

Details

The relative global deviation is the ratio between var1/var2 and ref (100 * (var1 / var2) / ref). Values greater than 100 indicate that the unit ratio is greater than the ratio of reference. Values lower than 100 indicate that the unit ratio is lower than the ratio of reference. The absolute global deviation is the amount of numerator that could be moved to obtain the ratio of reference on all units. ((var1 - (ref * var2)).

Examples

Run this code
# NOT RUN {
library(sf)
library(cartography)
# load data
data("GrandParisMetropole")

# compute absolute global deviation
com$gdevabs <- gdev(x = com, var1 = "INC", var2 = "TH", type = "abs")
# compute relative global deviation
com$gdevrel <- gdev(x = com, var1 = "INC", var2 = "TH", type = "rel")

# Deviations maps
# set graphical parameters
par(mar = c(0,0,1.2,0))
# set breaks
bks <- c(min(com$gdevrel),50,75,100,125,150,max(com$gdevrel))
# set color palette
cols <- carto.pal(pal1 = "blue.pal", n1 = 3,
                  pal2 = "wine.pal", n2 = 3)
# plot a choropleth map of the relative global deviation
choroLayer(x = com, var = "gdevrel",
           legend.pos = "topleft",
           legend.title.txt = "Relative Deviation\n(100 = general average)",
           breaks = bks, border = NA,
           col = cols)
# add symbols proportional to the absolute general deviation
com$sign <- ifelse(test = com$gdevabs<0, yes = "negative", no = "positive")
propSymbolsTypoLayer(x = com, var = "gdevabs",var2 = "sign",
                     legend.var.pos = "left",legend.values.rnd = -2,
                     legend.var2.values.order = c("positive", "negative"),
                     legend.var.title.txt = "Absolute Deviation\n(Income redistribution)",
                     col = c("#ff000050","#0000ff50"),legend.var2.pos = "n",
                     legend.var.style = "e", inches = 0.2)
# add EPT boundaries
plot(st_geometry(ept), add=TRUE)
# add a layout
layoutLayer(title = "General Deviation (reference: Grand Paris Metropole)",
            sources = "GEOFLA<U+00AE> 2015 v2.1, Apur, impots.gouv.fr",
            north = TRUE, scale = 5, tabtitle = TRUE, frame = FALSE, theme = "red.pal",
            author = "MTA")
# }

Run the code above in your browser using DataLab