View source: R/communes__ch_geographicalLevels.R
loadCommunesCHgeographicalLevels | R Documentation |
Load the Swiss statistical office geographical levels communes data from: https://www.bfs.admin.ch/bfs/fr/home/bases-statistiques/niveaux-geographiques.html. They have now an interactive app, export the Excel file from https://www.bfs.admin.ch/bfs/fr/home/bases-statistiques/niveaux-geographiques.html (check everything) and rename it as: niveaux_geographiques_communes.xlsx
loadCommunesCHgeographicalLevels()
The portrait includes non political OFS ID, i.e. lakes
a data.frame with tons of geographical features, check the source excel for more details
Typologie des communes et typologie urbain-rural 2012: https://www.bfs.admin.ch/bfs/fr/home/actualites/quoi-de-neuf.assetdetail.2543324.html
data <- loadCommunesCHgeographicalLevels()
# Plot map of typologie urbainrural 2012 at the municipality level
## Not run:
require(tidyverse)
require(sf)
glimpse(data)
data <- data %>%
select(ofsID, name,
`Typologie des communes 2012 (9 types) (Typologie des communes 2012 (25, 9 catégories et typologie urbain-rural))`)
# get the geographical data
require(tidyverse)
require(sf)
# loop and load the geo data in a named list
shp_ch_paths_2023 <- shp_path(2023)
shp_ch_geodata <- shp_ch_paths_2023 %>% map(function(x) {
layerName <- st_layers(x)
st_read(x, layer = layerName$name) %>%
select(ends_with("NR"), ends_with("NAME"))
})
shp_ch_geodata$municipalities <- left_join(
shp_ch_geodata$municipalities, data, by= c('GMDNR' = 'ofsID')) %>%
rename(`Typologie urbainrural 2012` =
`Typologie des communes 2012 (9 types) (Typologie des communes 2012 (25, 9 catégories et typologie urbain-rural))`) %>%
mutate(`Typologie urbainrural 2012` = as.factor(`Typologie urbainrural 2012`))
ggplot() +
geom_sf(data = shp_ch_geodata$municipalities,
aes(fill = `Typologie urbainrural 2012`), lwd = 0.05, colour = "#0d0d0d") +
geom_sf(data = shp_ch_geodata$cantons, lwd = 0.15, colour = "#333333", fill = NA) +
geom_sf(data = shp_ch_geodata$country, lwd = 0.25, colour = "#000d1a", fill = NA) +
geom_sf(data = shp_ch_geodata$lakes, lwd = 0, fill = "#0066cc") +
theme_map()
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.