-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
121 lines (90 loc) · 4.71 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# dePlzMap
<!-- badges: start -->
<!-- badges: end -->
<img src="man/figures/dePlzMap.png" width="270px" align="right" />
The `dePlzMap` R package is a tool for visualizing data on a map of Germany,
using postal code (PLZ) boundaries as geographic units.
The package defines the function `dePlzMap`, which provides a simple and flexible interface for creating [choropleth maps](https://en.wikipedia.org/wiki/Choropleth_map) of
PLZ regions in Germany with continuous color scales,
allowing users to explore spatial patterns and relationships in data.
It is also possible to normalize the input values by population
per PLZ region to show population-relative values.
The package leverages the `ggplot2` and `ggmap` libraries for generating the plots.
The necessary geographical data and data about the regions and the population is integrated in the package.
## Data
The population data is based on the data from the ["Registerzensus 2011"](https://www.zensus2011.de/DE/Home/Aktuelles/DemografischeGrunddaten.html?nn=559100) of the
Statistisches Bundesamt in Deutschland and was obtained from the web site [https://www.suche-postleitzahl.org](https://www.suche-postleitzahl.org/downloads).
The shape files that describe the borders of the PLZ regions have also been
drawn from [https://www.suche-postleitzahl.org](https://www.suche-postleitzahl.org/downloads).
The shape data for the borders of the German states is from https://public.opendatasoft.com/.
## Licensing
The geographic data used by the package
is derived from [OpenStreetMap](https://www.openstreetmap.org/) and is available under the
[Open Database License](https://opendatacommons.org/licenses/odbl/)
(© OpenStreetMap contributors).
The population data is copyrighted by Statistisches Bundesamt (2014), which
allows the distribution of the data, also in parts, if the source is specified.
Apart from the data, the package is licensed under the MIT license (© Stefan Lenz 2023).
## Installation
You can install the `dePlzMap` package from [GitHub](https://github.com/) in R via:
``` r
# install.packages("devtools")
devtools::install_github("stefan-m-lenz/dePlzMap")
```
## Usage
For demonstration purposes load the package together with some example data included in the package:
```{r LoadPackageAndData}
library(dePlzMap)
populationData <- read.table(system.file("extdata", "populationData.csv", package = "dePlzMap"),
sep =",", header = TRUE,
colClasses = c("character", "integer", "character"),
encoding = "UTF-8")
```
The CSV file contains information about the number of inhabitants for each of
the PLZ regions and the information in which federal state (Bundesland) the PLZ
region is located.
```{r ShowPopulationData}
head(populationData)
```
This data can now be used to display the population per PLZ region in Germany.
For this purpose, only the columns `plz` and `Population` of the
`populationData` data frame are needed:
```{r PopulationDE, dev = "png", out.width = "600px"}
dePlzMap(data = populationData[, c("plz", "Population")],
title = "Bevölkerung in Deutschland 2011", legendTitle = "Einwohner")
```
If only a single state or a specific set of states should be shown,
the argument `bundesland` can be specified:
```{r RLPPlot, dev = "png", out.width = "600px"}
dePlzMap(data = populationData[, c("plz", "Population")],
bundesland = "Rheinland-Pfalz",
title = "Bevölkerung in Rheinland-Pfalz", legendTitle = "Einwohner")
```
It is also possible to color the regions according to categorical values.
In the next example, the PLZ regions are colored according to the state
they are associated with.
If you look closely, you you can see here that there are a few PLZ regions
that go across federal state boundaries, e.g., in Hamburg or Brandenburg.
```{r BundeslaenderPlot, dev = "png", out.width = "600px"}
dePlzMap(data = populationData[, c("plz", "Bundesland")],
bundeslandBorderColor = "black") +
ggplot2::scale_fill_manual(values = rainbow(16))
```
As the resulting object is a `gpplot` object, the appearance
can be manipulated further via the `+` operation, e.g. by changing the color
palette for the discrete values like demonstrated above.
There are also several options for further customizing the plot
via arguments of the `dePlzMap` function.
More information about the arguments can be found in the [package manual](https://github.com/stefan-m-lenz/dePlzMap/releases/download/v1.0.0/dePlzMap.pdf).