MyNixOS website logo
Description

Plot Summary Statistics as Choropleth Maps of Danish Administrative Areas.

Provides a ggplot2 front end to plot summary statistics on danish provinces, regions, municipalities, and zipcodes. The needed geoms of each of the four levels are inherent in the package, thus making these types of plots easy for the user. This is essentially an updated port of the previously available 'mapDK' package by Sebastian Barfort.

plotDK

plotDK provides easy access to plot summary statistics as choropleth maps of danish administrative areas. plotDK supports geoms for danish regions, provices, municipalities, and zipcodes.

Installation

You can install the released version of plotDK from CRAN with:

install.packages("plotDK")

or from github with:

devtools::install_github("https://github.com/kristianSN/plotDK")

Empty maps

To simply show a choropleth map of a chosen administrative level (here regions) invoke:

library(plotDK)

plotDK(plotlevel = "region")

Switching to plot municipalities is as simply as switching the plotlevel to “municipality”:

plotDK(plotlevel = "municipality")

Plotting summary statistics on municipalities

To fill the maps with values, first generate or load a data set containing one row per entity, with a valid ID column and a value column to be plotted. plotDK contains information of valid ID’s. For municipalities this data is saved in:

plotDK::municipality_info

Here let’s generate a dataset with valid region ID’s and assign each region a random numeric value:

valid_ids <- plotDK::municipality_info

municipality_data <- data.frame(
  municipality_name = valid_ids$municipality_names,
  numeric_value = sample(1:100, size = length(valid_ids$municipality_names), replace = TRUE),
  stringsAsFactors = FALSE
)

municipality_data[1:20,]
#>    municipality_name numeric_value
#> 1           aabenraa             8
#> 2            aalborg            52
#> 3                ærø            17
#> 4        albertslund           100
#> 5            allerød            89
#> 6             aarhus            47
#> 7             assens            59
#> 8           ballerup            45
#> 9            billund            60
#> 10          bornholm            20
#> 11           brøndby            28
#> 12       brønderslev           100
#> 13       christiansø            45
#> 14            dragør            98
#> 15            egedal            81
#> 16           esbjerg             1
#> 17   faaborg-midtfyn            36
#> 18              fanø            76
#> 19          favrskov            75
#> 20              faxe            78

Plotting these values on their municipalities is as simple as providing the municipality data to plotDK(), while providing the names of the ID and value variables:

plotDK::plotDK(
  data = municipality_data,
  id = "municipality_name",
  value = "numeric_value",
  plotlevel = "municipality"
)

The value scales depends upon the type of the value variable. That is means if we try to plot a character or factor variable, the plot will change accordingly:

municipality_data <- data.frame(
  municipality_name = valid_ids$municipality_names,
  factor_value = factor(sample(c("a", "b"), size = length(valid_ids$municipality_names), replace = TRUE)),
  stringsAsFactors = FALSE
)

plotDK::plotDK(
  data = municipality_data,
  id = "municipality_name",
  value = "factor_value",
  plotlevel = "municipality"
)

ggplot compatability

The resulting plots are ggplot2-objects. This means that they can be altered or styled with normal ggplot elements:

library(ggplot2)
p <- plotDK::plotDK(
  data = municipality_data,
  id = "municipality_name",
  value = "factor_value",
  plotlevel = "municipality"
)

p + 
  ggtitle("Some title") +
  scale_fill_manual(
    values=c("firebrick", "darkgoldenrod"),
    name = "Letters"
  ) + 
  theme(
    panel.background = element_rect(
      fill = "lightblue"
    )
  )

Subplots

By default plotDK does not show missing entities. This means that subplots can easily be drawn, by only providing a subset of entities in the data:

zipcode_data <- plotDK::zipcode_info

zipcode_subset <- zipcode_data[zipcode_data$zipcode_numbers < 3000, , drop = FALSE]  

zipcode_subset$numeric_value <- sample(1:100, size = nrow(zipcode_subset), replace = TRUE)

p <- plotDK::plotDK(
  data = zipcode_subset,
  id = "zipcode_numbers",
  value = "numeric_value",
  plotlevel = "zipcode"
)
p

If you only have data on a subset of entities, but want the entire map drawn, do this by passing the argument; show_missing = TRUE:

p <- plotDK::plotDK(
  data = zipcode_subset,
  id = "zipcode_numbers",
  value = "numeric_value",
  plotlevel = "zipcode",
  show_missing = TRUE
)

p
Metadata

Version

0.1.0

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows