View source: R/cantonal_ch_indicators.R
loadCantonsCHportraits | R Documentation |
Load socio-demographic data by the Swiss Statistical Office.
loadCantonsCHportraits(file = "cantonal_CH_2020_indicators_je-f-21.03.02.csv")
file |
the name of the csv file to load (output by |
Run processPortraitsRegionauxCantons() to generate a readable csv file for loadCantonsCHportraits
a data.frame
cantonalI <- loadCantonsCHportraits()
## Not run:
require(geofacet)
## plot with geofacet the share the highest education reached by canton
# wrangle data
edu <- cantonalI %>%
select(`Sans formation postobligatoire (dès 25 ans)`,
`Degré secondaire II (dès 25 ans)`,
`Degré tertiaire (dès 25 ans)`) %>%
rownames_to_column()
stopifnot(all(rowSums(edu %>% select(-rowname)) %>% round() == 100))
colnames(edu) <- gsub(" \\(dès 25 ans\\)", "", colnames(edu))
edu <- edu %>% gather(education, pourc, -rowname) %>%
rename(code = rowname) %>%
mutate(education = fct_inorder(education))
# Plot
ggplot(edu) +
geom_col(aes(x = education, y = pourc, fill = education)) +
coord_flip() +
facet_geo( ~ code, grid = ch_cantons_grid2, label = "name_fr") +
scale_x_discrete(labels = NULL, name ="") +
scale_y_continuous(name = "") +
theme(legend.position = "top") +
ggtitle("Niveau d'éducation atteint par canton")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.