Learn R Programming

emdi (version 1.1.1)

map_plot: Visualizes regional disaggregrated estimates on a map

Description

Function map_plot creates spatial visualizations of the estimates obtained by small area estimation methods or direct estimation.

Usage

map_plot(object, indicator = "all", MSE = FALSE, CV = FALSE,
  map_obj = NULL, map_dom_id = NULL, map_tab = NULL, col = c("white",
  "red4"), scale_points = NULL, return_data = FALSE)

Arguments

object

an object of type emdi, containing the estimates to be visualized.

indicator

optional character vector that selects which indicators shall be returned: (i) all calculated indicators ("all"); (ii) each indicator name: "Mean" "Quantile_10", "Quantile_25", "Median", "Quantile_75", "Quantile_90", "Head_Count", "Poverty_Gap", "Gini", "Quintile_Share" or the function name/s of "custom_indicator/s"; (iii) groups of indicators: "Quantiles", "Poverty" or "Inequality". Defaults to "all". Note, additional custom indicators can be defined as argument for estimation approaches (see also direct and ebp) and do not appear in groups of indicators even though these might belong to one of the groups.

MSE

optional logical. If TRUE, the MSE is also visualized. Defaults to FALSE.

CV

optional logical. If TRUE, the CV is also visualized. Defaults to FALSE.

map_obj

a SpatialPolygonsDataFrame object as defined by the sp package on which the data should be visualized.

map_dom_id

a character string containing the name of a variable in map_obj that indicates the domains.

map_tab

a data.frame object with two columns that match the domain variable from the census data set (first column) with the domain variable in the map_obj (second column). This should only be used if the IDs in both objects differ.

col

a vector of length 2 defining the lowest and highest color in the plots.

scale_points

a structure defining the lowest, the mid and the highest value of the colorscale. If a numeric vector of length two is given, this scale will be used for every plot. Alternatively a list defining colors for each plot seperatly may be given. Please see the examples for this.

return_data

if set to TRUE a fortified data frame including the map data as well as the chosen indicators is returned. Customized can easily be obtained from this data frame via the package ggmap. Defaults to FALSE.

Value

Creates the map plots demanded.

See Also

ebp, emdiObject, readShapePoly

Examples

Run this code
# NOT RUN {
# Loading data - population and sample data
data("eusilcA_pop")
data("eusilcA_smp")

# generate emdi object with additional indicators; here via function ebp()
emdi_model <- ebp(fixed = eqIncome ~ gender + eqsize + cash + 
self_empl + unempl_ben + age_ben + surv_ben + sick_ben + dis_ben + rent + 
fam_allow + house_allow + cap_inv + tax_adj, pop_data = eusilcA_pop,
pop_domains = "district", smp_data = eusilcA_smp, smp_domains = "district",
threshold = 11064.82, transformation = "box.cox", L = 50, MSE = TRUE, B = 50, 
custom_indicator = list( my_max = function(y, threshold){max(y)},
my_min = function(y, threshold){min(y)}), na.rm = TRUE, cpus = 1)

# Load shape file
load_shapeaustria()

# Create mapping table such that variables that indicate domains correspond
# in population data and shape file
mapping_table <- data.frame(unique(eusilcA_pop$district), 
unique(shape_austria_dis$NAME_2))

# Example 1: Create map plot for mean indicator - point and MSE estimates 
# but no CV
map_plot(object = emdi_model, MSE = TRUE, CV = FALSE, 
map_obj = shape_austria_dis, indicator = c("Mean"), map_dom_id = "NAME_2", 
map_tab = mapping_table)

# Example 2:
# Now we are creating plots for the Mean and the Median with both their precision
# measures, while forcing coloring ranges of both indicators to be the same

# First, define appropriate scales for each indicator and measure and save it 
# in a nested list as seen below

my_scale_points <- list(Mean   = list(ind = c(0, 75000),
                                    MSE = c(45000, 15000000),
                                    CV  = c(0, 0.5)
                                   ),
                        Median = list(ind = c(0, 75000),
                                      MSE = c(45000, 15000000),
                                      CV  = c(0, 0.5)
                                   )
                       )
 # When done so, this list may be used as an argument to map_plot 
 
 map_plot(object = emdi_model, MSE = TRUE, CV = TRUE, 
          map_obj = shape_austria_dis, indicator = c("Mean", "Median"), 
          map_dom_id = "NAME_2", map_tab = mapping_table, 
          scale_points = my_scale_points)
 
 # Example 3:
 # In the simple case, that all plots shall use the same color range,
 # the procedure from example 2 may be abbreviated to:
 map_plot(object = emdi_model, MSE = FALSE, CV = FALSE, 
          map_obj = shape_austria_dis, indicator = c("Mean", "Median"), 
          map_dom_id = "NAME_2", map_tab = mapping_table, 
          scale_points = c(0, 75000))
# }

Run the code above in your browser using DataLab