title: "SCB example" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Vignette Title} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8}
SCB example
library(scbapi) r <- scb_api("ssd") r
scb_api("ssd/BE")
scb_api("ssd/BE/BE0101") scb_api("ssd/BE/BE0101/BE0101A")
r <- scb_api("ssd/BE/BE0101/BE0101A/FolkmangdTatortH") res <- r$get()
head(res)
library(dplyr) library(tidyr) library(stringr) dd <- res %>% gather(year, pop, Population.1960:Population.1980) %>% mutate( year = str_extract(year, "[0-9]{4}") %>% as.integer(), county = str_extract(region, "[\\(\\) A-ZÅÄÖa-zåäö\\*]*$") %>% str_replace_all("[\\(\\)]", ""), pop = as.integer(pop) ) %>% tbl_df() dd ddd <- dd %>% group_by(county, year) %>% summarise(pop = sum(pop, na.rm = TRUE))
library(ggplot2) ids <- sample(unique(ddd$county[ddd$year == 1965]), 4) d <- ddd %>% filter(county %in% ids) ggplot(d, aes(year, pop, color = county, group = county)) + geom_line() + theme(legend.position = "bottom") + theme_bw()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.