Giter VIP home page Giter VIP logo

deplzmap's Introduction

dePlzMap

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 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” of the Statistisches Bundesamt in Deutschland and was obtained from the web site https://www.suche-postleitzahl.org.

The shape files that describe the borders of the PLZ regions have also been drawn from https://www.suche-postleitzahl.org.

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 and is available under the Open Database License (© 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 in R via:

# 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:

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.

head(populationData)
#>     plz Population Bundesland
#> 1 01067      11957    Sachsen
#> 2 01069      25491    Sachsen
#> 3 01097      14821    Sachsen
#> 4 01099      28018    Sachsen
#> 5 01108       5876    Sachsen
#> 6 01109      20010    Sachsen

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:

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:

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.

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.

deplzmap's People

Contributors

stefan-m-lenz avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.