Geocomputation with R

Introduction

This repository hosts the code underlying Geocomputation with R, a book by Robin Lovelace, Jakub Nowosad, and Jannes Muenchow.

The online version of the book is developed at https://geocompr.robinlovelace.net/. We plan to publish the hard copy of the book with CRC Press in 2018.

Contributing

We encourage contributions on any part of the book, including:

  • Improvements to the text, e.g. clarifying unclear sentences, fixing typos (see guidance from Yihui Xie).
  • Changes to the code, e.g. to do things in a more efficient way.
  • Suggestions on content (see the project's issue tracker and the work-in-progress folder for chapters in the pipeline).

Please see our-style.md for the book's style.

Many thanks to all contributors to the book so far via GitHub (this list will update automatically): katygregg, erstearns, eyesofbambi, rsbivand, pat-s, gisma, ateucher, gavinsimpson, yutannihilation, mvl22, richfitz, wdearden, gregor-d, p-kono, pokyah.

During the project we aim to contribute 'upstream' to the packages that make geocomputation with R possible. This impact is recorded in our-impact.csv.

Reproducing the book

To ease reproducibility, this book is also a package. Installing it from GitHub will ensure all dependencies to build the book are available on your computer (you need devtools):

devtools::install_github("robinlovelace/geocompr")

You need a recent version of the GDAL, GEOS, Proj.4 and UDUNITS libraries installed for this to work on Mac and Linux. See the sf package's README for information on that.

Once the dependencies have been installed you should be able to build and view a local version the book with:

bookdown::render_book("index.Rmd") # to build the book
browseURL("_book/index.html") # to view it

The code associated with each chapter is saved in the code/chapters/ folder. source("code/chapters/07-transport.R") runs run the code chunks in chapter 7, for example. These R scripts are generated with the follow command which wraps knitr::purl():

# geocompr:::generate_chapter_code()

Running the book in docker

To ease reproducibility we have set-up a docker image containing all the dependencies needed to reproduce the book. After you have installed docker and set-it up on your computer you should be able to reproduce the entire book with the following steps (resulting in output shown below):

# from a system terminal such as Windows Powershell or a Unix terminal
git clone https://github.com/Robinlovelace/geocompr.git # download the repo
cd .\geocompr\ # navigate into the repo
docker run -d -p 8787:8787 -v ${pwd}:/data robinlovelace/geocompr

If it worked you should be able to open-up RStudio server by opening a browser and navigating to http://localhost:8787/ resulting in an up-to-date version of R and RStudio running in a container:

geocompr in docker: Illustration of how it should look if it worked!

From this point to build the book you need to navigate to the volume location on docker machine, by opening the project at /data from the project box in the top-right hand corner, illustrated in the figure below. From here open the file index.Rmd and hit the little knit button above the the RStudio script panel (above the book text on line 81 illustrated in the image above).

Opening the project: navigate to the volume folder in docker (or in another location on your computer)

Reproducing this README

To reduce the book's dependencies, scripts to be run infrequently to generate input for the book are run on creation of this README.

The additional packages required for this can be installed as follows:

source("code/extra-pkgs.R")

With these additional dependencies installed, you should be able to run the following scripts, which create content for the book, that we've removed from the main book build to reduce package dependencies and the book's build time:

source("code/cranlogs.R")
source("code/sf-revdep.R")
# source("code/09-usboundaries.R") # not working for some reason
source("code/09-urban-animation.R")
source("code/09-map-pkgs.R")

Note: the .Rproj file is configured to build a website not a single page. To reproduce this README use the following command:

rmarkdown::render("README.Rmd", output_format = "github_document", output_file = "README.md")

Book statistics

An indication of the book's progress over time is illustrated below (to be updated roughly every week as the book progresses).

Book statistics: estimated number of pages per chapter over time.

Citations

To cite packages used in this book we use code from Efficient R Programming:

geocompr:::generate_citations()

This generates .bib and .csv files containing the packages. The current of packages used can be read-in as follows:

pkg_df = readr::read_csv("extdata/package_list.csv")

Other citations are stored online using Zotero.

If you would like to add to the references, please use Zotero, join the open group add your citation to the open geocompr library.

We use the following citation key format:

[auth:lower]_[veryshorttitle:lower]_[year]

This can be set from inside Zotero desktop with the Better Bibtex plugin installed (see github.com/retorquere/zotero-better-bibtex) by selecting the following menu options (with the shortcut Alt+E followed by N), and as illustrated in the figure below:

Edit > Preferences > Better Bibtex

Zotero settings: these are useful if you want to add references.

We use Zotero because it is a powerful open source reference manager that integrates well with the citr package. As described in the GitHub repo Robinlovelace/rmarkdown-citr-demo.

References

knitr::kable(pkg_df)
NameTitleversion
bookdownAuthoring Books and Technical Documents with R Markdown [@R-bookdown]0.7.8
cartogramCreate Cartograms with R [@R-cartogram]0.0.3
dismoSpecies Distribution Modeling [@R-dismo]1.1.4
geosphereSpherical Trigonometry [@R-geosphere]1.5.7
ggmapSpatial Visualization with ggplot2 [@R-ggmap]2.6.1
ggplot2Create Elegant Data Visualisations Using the Grammar of Graphics [@R-ggplot2]2.2.1.9000
gstatSpatial and Spatio-Temporal Geostatistical Modelling, Prediction [@R-gstat]1.1.6
historydataData Sets for Historians [@R-historydata]0.2.9001
htmlwidgetsHTML Widgets for R [@R-htmlwidgets]1.2
kableExtraConstruct Complex Table with 'kable' and Pipe Syntax [@R-kableExtra]0.8.0
knitrA General-Purpose Package for Dynamic Report Generation in R [@R-knitr]1.20
leafletCreate Interactive Web Maps with the JavaScript 'Leaflet' [@R-leaflet]2.0.0
link2GILinking Geographic Information Systems, Remote Sensing and Other [@R-link2GI]0.3.0
lwgeomBindings to Selected 'liblwgeom' Functions for Simple Features [@R-lwgeom]0.1.5
mapviewInteractive Viewing of Spatial Data in R [@R-mapview]2.3.7
microbenchmarkAccurate Timing Functions [@R-microbenchmark]1.4.4
mlrMachine Learning in R [@R-mlr]2.12.1
osmdataImport 'OpenStreetMap' Data as Simple Features or Spatial [@R-osmdata]0.0.6.1
pROCDisplay and Analyze ROC Curves [@R-pROC]1.11.0
rasterGeographic Data Analysis and Modeling [@R-raster]2.6.7
rcartocolor'CARTOColors' Palettes [@R-rcartocolor]0.0.22
rgdalBindings for the 'Geospatial' Data Abstraction Library [@R-rgdal]1.2.18
rgeosInterface to Geometry Engine - Open Source ('GEOS') [@R-rgeos]0.3.26
rmapshaperClient for 'mapshaper' for 'Geospatial' Operations [@R-rmapshaper]0.4.0
rmarkdownDynamic Documents for R [@R-rmarkdown]1.9
rnaturalearthWorld Map Data from Natural Earth [@R-rnaturalearth]0.1.0
rnaturalearthdataWorld Vector Map Data from Natural Earth Used in 'rnaturalearth' [@R-rnaturalearthdata]0.1.0
RQGISIntegrating R with QGIS [@R-RQGIS]1.0.3.9000
RSAGASAGA Geoprocessing and Terrain Analysis [@R-RSAGA]1.1.0
sfSimple Features for R [@R-sf]0.6.3
spClasses and Methods for Spatial Data [@R-sp]1.2.7
spDataDatasets for Spatial Analysis [@R-spData]0.2.8.8
spDataLargeLarge datasets for spatial analysis [@R-spDataLarge]0.2.6.3
stplanrSustainable Transport Planning [@R-stplanr]0.2.4
tabularasterTidy Tools for 'Raster' Data [@R-tabularaster]0.4.0
tidyverseEasily Install and Load the 'Tidyverse' [@R-tidyverse]1.2.1
tmapThematic Maps [@R-tmap]2.0
tmaptoolsThematic Map Tools [@R-tmaptools]2.0

Copy Link

Version

Down Chevron

Version

0.0.59

License

Issues

Pull Requests

Stars

Forks

Maintainer

Last Published

January 1st, 1970