Author

Peter Baumgartner

Published

2025-02-02 18:29

Preface

This is work in progress

I have finished about 14%. Currently I am working on Chapter 3 (Attribute data operations).

WATCH OUT: This is my personal learning material and is therefore neither an accurate replication nor an authoritative textbook.

I am writing this book as a text for others to read because that forces me to become explicit and explain all my learning outcomes more carefully. Please keep in mind that this text is not written by an expert but by a learner.

Text passages with content I am already familiar I have skipped. Section of the original text where I needed more in-depth knowledge I have elaborated and added my own comments resulted from my personal research.

Be warned! In spite of replicating most of the content this Quarto book may contain many mistakes. All the misapprehensions and errors are of course my own responsibility.

Content and Goals of this Book

This Quarto book collects my personal notes, trials and exercises of Geocomputation with R by (Lovelace, Nowosad, and Muenchow 2025).

I have no previous experience with geocomputing. I am not planning to get an expert in geocomputing but I need some basic knowledge to display my research results as choropleth maps or cartograms.

Text passages

Quotes and personal comments

My text in these notes consists mostly of quotes from the geomcomputation book. Sometimes I have them changed slightly to adpat it to the flow onf my notes. But I have not referenced the poistion of the (semi)quotes in the book. As I am generally follow the book’s outline using the same text for headers, it should be clear where to find the quotes.

This means that most of the text in this Quarto book is not mine but comes from different resources.

My personal comments should be clear because most of the times it is a reflection about the book and my experiences with it.

Glossary

I am using the {glossary} package to create links to glossary entries.]

R Code 1 : Load glossary

Listing / Output 1: Install and load the glossary package with the appropriate glossary.yml file
## 1. Install the glossary package:
## https://debruine.github.io/glossary/

library(glossary)

## If you want to use my glossary.yml file:

## 1. fork my repo
##    https://github.com/petzi53/glossary-pb

## 2. Download the `glossary.yml` file from
##    https://github.com/petzi53/glossary-pb/blob/master/glossary.yml)

## 3. Store the file on your hard disk
##    and change the following path accordingly

glossary::glossary_path("../glossary-pb/glossary.yml")

If you hover with your mouse over the double underlined links it opens an window with the appropriate glossary text. Try this example: Z-Score.

WATCH OUT! Glossary is my private learning vehicle

I have added many of the glossary entries when I was working through other books either taking the text passage of these books I was reading or via an internet recherche from other resources. Sometimes I have added the source of the glossary entry as an abbreviation or as an URL. Many definitions were provided by the KI provided within the search of my Brave browser.

If you fork the the repo of this book then the glossary will not work out of the box. Load down the glossary.yml file from my glossary-pb GitHub repo, store it on your hard disk and change the path in the code chunk Listing / Output 1 accordingly.

In any case I am the only responsible person for the glossary text, especially if I have used text from other resources wrongly. Again: The main purpose of the glossary is to support my persponal learning venture.

R Code and Datasets

During coding I am following the Tidyverse Style Guide. But for learning purposes I am trying to prefix all functions with the package name in the format :: (e.g., dplyr::filter()) This is an overhead but supports me to understand which packages is responsible for which action.

Sometimes adding just the package name does not work. This is mostly the case when a generic function name like plot is used by another package in a more specialized manner. In this case I will try to use the function of the package. If this doesn’t work too then I have to come back to the standard usage of base::library(<package-name>).

I am using the package name also for the default installation of base R. This wouldn’t be necessary but it helps me to understand where the base R functions come from. What follows is a list of base R packages of the system library included into every installation and attached (opened) by default:

  • {base}: The R Base Package
  • {datsets}: The R Datasets Package
  • {graphics}: The R Graphics Package
  • {grDevices}: The R Graphics Devices and Support for Colours and Fonts
  • {methods}: Formal Methods and Classes
  • {stats}: The R Stats Package
  • {utils}: The R Utils Package

I am not using always the exact code snippets for my replications because I am not only replicating the code to see how it works but also to change the values of parameters to observe their influences.

When it is clear then I will follow the advice from Hadley Wickham:

When you call a function, you typically omit the names of data arguments, because they are used so commonly. If you override the default value of an argument, use the full name (tidyverse style guide).

Annex

In some of my book notes I provide files in the annex. They contain experiments not directly in line with the book but inspired by my reading of the book.

Often you will also find an annex file with a standardized short description of all my used packages, sometimes added with notes about my personal experiences with this package. An example of the standardized format gives you the following Glossary package.

Glossary package

Package Profile: glossary

{glossary}: Glossaries for Markdown and Quarto Documents (DeBruine 2023)

Add glossaries to markdown and quarto documents by tagging individual words. Definitions can be provided inline or in a separate file.

There is a lot of necessary jargon to learn reading new books. The goal of {glossary} is to provide a lightweight solution for making glossaries in educational materials written in quarto or R Markdown. This package provides functions to link terms in text to their definitions in an external glossary file, as well as create a glossary table of all linked terms at the end of a section.


In the meantime {glossary} is for me a very important learning vehicle. Whenever an expression appears with a doubled underlined link I know that I will get more information by hovering the mouse over the underlined text.

There is a little inconvenience with abrreviation that could also be part of another glossary entry text string (e.g., API and Capital Income). My workaround is to end the short abbreviation with an additional ‘x’ and then to call the glossary with the x-version follwed by the text that should be appear in the document (e.g., r glossary(“APIx”, “API”)). This double format is a standard feature of the {glossary} package so that you can adapt the appearing text to the glossary entry (e.g., singular/plural or other grammar changes).

Resources

Essential resources

Resource 1 : Resources used for this Quarto book

  • Lovelace, R., Nowosad, J., & Muenchow, J. (2025). Geocomputation With R (2nd ed.). Chapman & Hall/CRC.
  • Lovelace, R., Nowosad, J., & Muenchow, J. (2025). Geocomputation with R. https://r.geocompx.org/
  • Lovelace, R., Nowosad, J., & Muenchow, J. (2022). Geocomputation with R: an open source book (Version 1.9.1-2) [R, Markdown]. https://github.com/geocompx/geocompr
  • Lovelace, R., Nowosad, J., & Muenchow, J. (2025). Geocomputation with R: Solutions. https://r.geocompx.org/solutions/
  • Lovelace, R., Nowosad, J., & Muenchow, J. (2021). Geocomputation with R (1st ed.). https://geocompr.robinlovelace.net/
  • Lovelace, R., Nowosad, J., & Muenchow, J. (2020). Geocomputation with R (1st ed.). Routledge.

Private Functions

I used several private functions to facilitate repetitive tasks. All these functions starts with my initials pb_ and can be found in “R/helper.R”

  • pb_create_folder(path): Check if the folder already exists at parameter “path”. If not, then create the folder.
  • pb_save_data_file(chapter_folder, object, file_name): Save the data file for the specified chapter folder. If the folder not exists, create it and save object as .rds file. the chapter folder is a folder inside the “data” folder

Glossary Entries of this Chapter

term definition
APIx An API, or application programming interface, is a set of defined rules that enable different applications to communicate with each other. It acts as an intermediary layer that processes data transfers between systems, letting companies open their application data and functionality to external third-party developers, business partners, and internal departments within their companies. (<a href="https://www.ibm.com/topics/api">IBM</a>)
Capital Income Capital income is defined as the sum of property income, including dividends, interest gains, reinvested earnings on foreign direct investment, investment income disbursements and land rents ([Distributional National Accounts (DINA) for Austria, 2004-2016](https://wid.world/document/distributional-national-accounts-dina-for-austria-2004-2016-world-inequality-lab-wp-2020-23/)).
Cartogram A cartogram is a type of map where the areas of regions or countries are distorted to represent a specific data value, such as population or economic size. This map distorts the geographic shapes to convey information about a thematic variable, making the area directly proportional to the data being represented rather than the actual land area. Cartograms are used to visualize data related to countries, regions, or states, such as population distribution, GDP, or electoral votes. They can be created using various techniques, including proportional symbol maps, where point features are scaled, or linear cartograms, where the weight of linear features is scaled. However, these techniques only scale the map symbols, not the space itself. Cartograms are particularly useful for displaying emphasis and minimizing natural distortions caused by our perception of real geography. They are often used as a base for other thematic mapping techniques like choropleth mapping.
Choropleth A choropleth map is a type of thematic map that uses shading or coloring to represent statistical data across predefined geographic regions. These regions can be political boundaries, such as states or countries, or natural divisions. Each area is colored based on the value of the variable being represented, typically using a gradient where darker shades indicate higher values and lighter shades indicate lower values. This visualization technique helps viewers quickly grasp patterns and trends within the dataset. It is important to note that choropleth maps can sometimes lead to misinterpretation due to the bias introduced by the size of the regions. Larger regions may appear to have more significance simply because of their size, even if their data values are the same as smaller regions. In this case use Cartograms.
Z-score A z-score (also called a standard score) gives you an idea of how far from the mean a data point is. But more technically it’s a measure of how many standard deviations below or above the population mean a raw score is. (<a href="https://www.statisticshowto.com/probability-and-statistics/z-score/#Whatisazscore">StatisticsHowTo</a>)

Session Info

Session Info

Code
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.4.2 (2024-10-31)
#>  os       macOS Sequoia 15.2
#>  system   x86_64, darwin20
#>  ui       X11
#>  language (EN)
#>  collate  en_US.UTF-8
#>  ctype    en_US.UTF-8
#>  tz       Europe/Vienna
#>  date     2025-01-31
#>  pandoc   3.6.2 @ /usr/local/bin/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version    date (UTC) lib source
#>  cli           3.6.3      2024-06-21 [1] CRAN (R 4.4.0)
#>  codetools     0.2-20     2024-03-31 [2] CRAN (R 4.4.2)
#>  colorspace    2.1-1      2024-07-26 [1] CRAN (R 4.4.0)
#>  commonmark    1.9.2      2024-10-04 [2] CRAN (R 4.4.1)
#>  curl          6.2.0      2025-01-23 [2] CRAN (R 4.4.1)
#>  digest        0.6.37     2024-08-19 [1] CRAN (R 4.4.1)
#>  evaluate      1.0.3      2025-01-10 [1] CRAN (R 4.4.1)
#>  fastmap       1.2.0      2024-05-15 [1] CRAN (R 4.4.0)
#>  glossary    * 1.0.0.9003 2024-08-05 [2] Github (debruine/glossary@05e4a61)
#>  glue          1.8.0      2024-09-30 [1] CRAN (R 4.4.1)
#>  htmltools     0.5.8.1    2024-04-04 [1] CRAN (R 4.4.0)
#>  htmlwidgets   1.6.4      2023-12-06 [1] CRAN (R 4.4.0)
#>  jsonlite      1.8.9      2024-09-20 [1] CRAN (R 4.4.1)
#>  kableExtra    1.4.0      2024-01-24 [2] CRAN (R 4.4.0)
#>  knitr         1.49       2024-11-08 [1] CRAN (R 4.4.1)
#>  lifecycle     1.0.4      2023-11-07 [1] CRAN (R 4.4.0)
#>  magrittr      2.0.3      2022-03-30 [1] CRAN (R 4.4.0)
#>  markdown      1.13       2024-06-04 [2] CRAN (R 4.4.0)
#>  munsell       0.5.1      2024-04-01 [1] CRAN (R 4.4.0)
#>  R6            2.5.1      2021-08-19 [1] CRAN (R 4.4.0)
#>  rlang         1.1.5      2025-01-17 [1] CRAN (R 4.4.1)
#>  rmarkdown     2.29       2024-11-04 [1] CRAN (R 4.4.1)
#>  rstudioapi    0.17.1     2024-10-22 [2] CRAN (R 4.4.1)
#>  rversions     2.1.2      2022-08-31 [2] CRAN (R 4.4.0)
#>  scales        1.3.0      2023-11-28 [1] CRAN (R 4.4.0)
#>  sessioninfo   1.2.2      2021-12-06 [2] CRAN (R 4.4.0)
#>  stringi       1.8.4      2024-05-06 [2] CRAN (R 4.4.0)
#>  stringr       1.5.1      2023-11-14 [2] CRAN (R 4.4.0)
#>  svglite       2.1.3      2023-12-08 [2] CRAN (R 4.4.0)
#>  systemfonts   1.2.1      2025-01-20 [2] CRAN (R 4.4.1)
#>  vctrs         0.6.5      2023-12-01 [1] CRAN (R 4.4.0)
#>  viridisLite   0.4.2      2023-05-02 [1] CRAN (R 4.4.0)
#>  xfun          0.50       2025-01-07 [1] CRAN (R 4.4.1)
#>  xml2          1.3.6      2023-12-04 [2] CRAN (R 4.4.0)
#>  yaml          2.3.10     2024-07-26 [1] CRAN (R 4.4.0)
#> 
#>  [1] /Library/Frameworks/R.framework/Versions/4.4-x86_64/library
#>  [2] /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────

References

DeBruine, Lisa. 2023. “Glossary: Glossaries for Markdown and Quarto Documents.” https://github.com/debruine/glossary.
Lovelace, Robin, Jakub Nowosad, and Jannes Muenchow. 2025. Geocomputation With R. 2nd ed. Boca Raton, FL: Chapman & Hall/CRC.