siane_merge: Merges data and maps

Description Usage Arguments Details Value Examples

View source: R/siane_merge.R

Description

This is a function that binds data to polygons

Usage

1
siane_merge(shp, df, by, level, value)

Arguments

shp

: A S4 object returned by the siane_map function.

df

: The data frame with the data we want to plot

by

: The name of the column that contains the ID's of the territories.

level

: The level of the territory.

value

: The statistical values's we want to plot. Only one value per territory.

Details

- shp is a S4 object returned by the siane_map function.
- df is a data frame. This data frame should have at least two columns: one column of statistical data and another column of territorial codes. There will be as many missing territories as missing codes in the dataframe.
- by is the dataframe's codes column. These codes should be the INE's official codes.
- For the level parameter you pick one of these: "Municipios", "Provincias", "Comunidades" . It's very important that this level is consistent with the S4 object level.
- value is the name of the column with the statistical values

Value

A S4 object with the statistical data provided.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
## Not run: 
library(pxR)
obj <- register_siane("/home/ncarvalho/Downloads/")
# Loading the municipality's map of Spain
shp <- siane_map(obj = obj, level = "Municipios", canarias = FALSE) 
plot(shp) # Plot the map
# Get this file in INE's website. Check the README to learn how to do it.
df <- as.data.frame(read.px("/home/ncarvalho/Downloads/2879.px"))
by <- "codes"
df[[by]] <- sapply(df$Municipios,function(x) strsplit(x = as.character(x), split = " ")[[1]][1])
year <- 2016
df$Periodo <- as.numeric(as.character(df$Periodo))
df <- df[df$Sex == "Total" & df$Periodo == year, ]
value <- "value"
level <- "Municipios"
shp_merged <- siane_merge(shp = shp, df = df,by = by, level = level, value = value)
plot(shp_merged)
## End(Not run)
 

Nuniemsis/Siane documentation built on May 21, 2019, 2:20 p.m.