Getting Started

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.

library(dawaR)

Getting regional data for Denmark

To get a dataframe of all the regions in Denmark, you can use the get_data() function.

get_data("regioner")

This will return data on each of the five regions.

Using DAWA to crosstab municipalities and their regions.

library(dplyr)

The function get_data() fetches the data in json format and by default transforms it to a data.frame.

library(dawaR)
library(dplyr)

municipalities <- get_data("kommuner")

nordjylland <- municipalities |>
  filter(regionsnavn == "Region Nordjylland") |>
  pull(navn)
nordjylland
#>  [1] "Morsø"           "Thisted"         "Brønderslev"     "Frederikshavn"  
#>  [5] "Vesthimmerlands" "Læsø"            "Rebild"          "Mariagerfjord"  
#>  [9] "Jammerbugt"      "Aalborg"         "Hjørring"

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}.

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").



Try the dawaR package in your browser

Any scripts or data that you put into this service are public.

dawaR documentation built on April 3, 2025, 10:35 p.m.