--- title: "Getting Started" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Getting Started} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r, include = FALSE} knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) ``` This package has multiple use cases, though they all revolve around data from the Danish Web Address API. If the below examples are not enough, please do read through the other vignettes. First we need to load the package. ```{r setup} library(dawaR) ``` ## Getting regional data for Denmark To get a dataframe of all the regions in Denmark, you can use the `get_data()` function. ```{r} get_data("regioner") ``` This will return data on each of the five regions. ### Using DAWA to crosstab municipalities and their regions. ```{r, include=FALSE} library(dplyr) ``` The function `get_data()` fetches the data in `json` format and by default transforms it to a data.frame. ```{r} library(dawaR) library(dplyr) municipalities <- get_data("kommuner") nordjylland <- municipalities |> filter(regionsnavn == "Region Nordjylland") |> pull(navn) nordjylland ``` Here we have extracted all the municipalities that are in "Region Nordjylland". The same can be done for voting precincts or police regions. It can also be done for addresses and others. Look through the available sections with `available_sections()`. ### Using DAWA map data The function `get_map_data()` fetches data in `geojson` format and transforms the geometries to `{sf}` polygons. These polygons can be drawn as nice maps with `{ggplot2}`. ```{r municipality_map} library(dawaR) library(ggplot2) municipalities <- get_map_data("kommuner") ggplot(municipalities, aes(fill = regionsnavn)) + geom_sf(color = "black") + labs(fill = "Region") + cowplot::theme_map() ``` For more information on how to plot maps with `{dawaR}` please consult `vignette("printing_maps")`.