Skip to content

Instantly share code, notes, and snippets.

@ties
Created July 25, 2019 09:55
Show Gist options
  • Save ties/521ba6f9bb78994c164fd6c07971b265 to your computer and use it in GitHub Desktop.
Save ties/521ba6f9bb78994c164fd6c07971b265 to your computer and use it in GitHub Desktop.
Een voorbeeld van CBS open data in combinatie met ggplot2
---
title: "Voorbeeld van CBS open data in combinatie met ggplot2"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
list.of.packages <- c(
"cbsodataR", "smooth", "zoo", "Mcomp", "svglite"
)
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)
library(dplyr) # not needed, but used in examples below
library(cbsodataR)
library(ggplot2)
library(tidyverse)
library(RColorBrewer)
library(lubridate)
theme_set(theme_bw())
```
```{r}
# 83451NED - Werkgelegenheid
werkgelegenheid_data <- cbs_get_data('83451NED') %>%
cbs_add_label_columns() %>%
cbs_add_date_column()
werkgelegenheid_ft_total <- werkgelegenheid_data %>%
filter(KenmerkenBaan_label == 'Totaal') %>%
filter(KenmerkenBaan_label == 'Totaal')
```
```{r}
print(werkgelegenheid_ft_total)
werkgelegenheid_data %>% distinct(BedrijfstakkenBranchesSBI2008_label)
# attributes(werkgelegenheid_ft_total)$names
```
```{r}
werkgelegenheid_ft_total %>% filter(BedrijfstakkenBranchesSBI2008_label == 'F Bouwnijverheid')
```
```{r}
fig <- werkgelegenheid_ft_total %>%
filter(
(BedrijfstakkenBranchesSBI2008_label == 'F Bouwnijverheid') |
(BedrijfstakkenBranchesSBI2008_label == 'O Openbaar bestuur en overheidsdiensten')
) %>% # Filter on construction industry and something that did not shrink a lot in recession
filter(Perioden_freq == 'M') %>% # By month
ggplot(aes(x=Perioden_Date, y=ArbeidsvolumeZonderSeizoenscorrectie_4, color=BedrijfstakkenBranchesSBI2008_label)) +
geom_line() +
scale_colour_brewer(type="qual", palette=2) + # http://colorbrewer2.org/ validated color scale
labs(
color='Sector',
x='Tijd',
y='Aantal voltijdsbanen',
title='Werkgelegenheid per sector'
)
print(fig)
ggsave('fig.pdf', fig, width=6, height=2)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment