map_plot {saeTrafo} | R Documentation |
Visualizes regional disaggregated estimates on a map
Description
Function map_plot
creates spatial visualizations of the estimates
obtained by small area estimation methods.
Usage
map_plot(
object,
MSE = FALSE,
CV = FALSE,
map_obj = NULL,
map_dom_id = NULL,
map_tab = NULL,
color = c("white", "red4"),
scale_points = NULL,
guide = "colourbar",
return_data = FALSE
)
Arguments
object |
an object of type |
MSE |
optional logical. If |
CV |
optional logical. If |
map_obj |
an |
map_dom_id |
a character string containing the name of a variable in
|
map_tab |
a |
color |
a |
scale_points |
a numeric vector of length two. This scale will be used for every plot. |
guide |
character passed to |
return_data |
if set to |
Value
Creates the plots demanded and, if selected, a fortified data.frame containing the mapdata and chosen indicators.
See Also
Examples
# Examples for creating maps to visualize the saeTrafo estimates
# Load Data
data("eusilcA_smp")
data("pop_area_size")
data("pop_mean")
data("pop_cov")
# Nested error regression model
NER_model <- NER_Trafo(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,
smp_domains = "district",
pop_area_size = pop_area_size,
pop_mean = pop_mean, pop_cov = pop_cov,
smp_data = eusilcA_smp, MSE = TRUE)
# Load shape file
load_shapeaustria()
# Example 1: Map plots with uncertainty plots (for MSE and CV)
map_plot(NER_model, MSE = TRUE, CV = TRUE, map_obj = shape_austria_dis,
map_dom_id = "PB")
# Example 2: Personalize map plot for point estimates
map_plot(NER_model, map_obj = shape_austria_dis, map_dom_id = "PB",
color = c("white", "darkblue"),
scale_points = c(0, max(NER_model$ind$Mean)))
# Example 3: More options to personalize map plot by using return_data = TRUE
# and ggplot2
require(ggplot2)
library(ggplot2)
data_plot <- map_plot(NER_model, map_obj = shape_austria_dis, map_dom_id = "PB",
return_data = TRUE)
ggplot(data_plot, aes(long = NULL, lat = NULL,
group = "PB", fill = Mean))+
geom_sf(color = "black") +
theme_void() +
ggtitle("Personalized map") +
scale_fill_gradient2(low = "red", mid = "white", high = "darkgreen",
midpoint = 20000)
# Example 4: Create a suitable mapping table to use numerical identifiers of
# the shape file
# First find the right order
dom_ord <- match(shape_austria_dis$PB, NER_model$ind$Domain)
#Create the mapping table based on the order obtained above
map_tab <- data.frame(pop_data_id = NER_model$ind$Domain[dom_ord],
shape_id = shape_austria_dis$BKZ)
# Create map plot for mean indicator - point and CV estimates but no MSE
# using the numerical domain identifiers of the shape file
map_plot(object = NER_model, MSE = FALSE, CV = TRUE,
map_obj = shape_austria_dis,
map_dom_id = "BKZ", map_tab = map_tab)