Description Usage Arguments Details Value Examples
This is a function that binds data to polygons
1 | siane_merge(shp, df, by, level, value)
|
shp |
: A S4 object returned by the |
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. |
- 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
A S4 object with the statistical data provided.
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.