Introduction
The goal of user2017.geodataviz is to privide a comprehensive overview of the options available in the R language for Geospatial data visualization. This was presented at useR! 2017 as a tutorial titled Geospatial visualization using R.
This tutorial covers …
R Packages for Spatial Analysis in R
Data Structures for Spatial Data in R
Operations Supported on Spatial Data
- Visualizing Spatial Data…
- Using Base Graphics
- Using
ggplot2
and helper packages - Using
shiny
for dynamic mapping - Using
leaflet
and related packages for interactive maps. - Using specialized packages such as
tmap
,choroplethr
,ggmap
,plotly
,highcharter
etc.
I will add more and more samples as time progresses so keep a tab on this repository from time to time.
Installation
Note You don’t need to install anything if you just want to watch the slides. The links to the slides and R Notebook HTMLs are in the section Slides and R Notebooks below.
The Docker Way
The easiest option is using a docker image built specifically for this tutorial.
Install docker, and docker toolbox (only for Windows and Mac).
Either using the kitematic GUI tool or command line pull the
bhaskarvk/rgeodataviz
image.
Command line:docker pull bhaskarvk/rgeodataviz
For the interested the docker image was built on top of rocker.
Manually
This tutorial is also an R package which enables you to pull in all the packages needed to run this tutorial. You can install all the needed packages simply by installing this package.
First start by cloning this git repository, or better yet fork this repository on github and pull your fork. That way you can push changes to your fork.
git clone https://github.com/bhaskarvk/user2017.geodataviz
# OR git pull <your forked repository>
cd user2017.geodataviz
Next start R
in this directory, and install this package and all its dependencies.
if(!require("devtools")) {
install.packages("devtools")
}
devtools::install(dependencies="Suggests")
That should pull in all the packages required, but be aware of the following points…
- The docker image has some more extra packages that were not used in the tutorial but available for you to use.
- The list of packages is quite big so installation can be slow.
- Some packages have dependencies on external libraries which you will need to install, otherwise the packages won’t compile if being built from source. The docker image comes with these packages pre-installed.
Up and Running
If you are using docker, then run the following command.
docker run -d -p 8787:8787 --name rgeodataviz bhaskarvk/rgeodataviz
This will start the docker container and you can connect to the Rstudio session using the URL ‘http://localhost:8787’, the userid/password are rstudio/rstudio
.
If you are running in a local environment you can simply open the user2017.geodataviz.Rproj
file from the user2017.geodataviz
directory which you checked-out using git above.
To stop and subsequently start the container again use
docker stop rgeodataviz
docker start rgeodataviz
Occasionally I will be pushing updates to the docker image. If you want the latest docker image you will have to destroy the existing container, pull the latest image and rerun the container.
docker stop rgeodataviz
docker container rm rgeodataviz
docker pull bhaskarvk/rgeodataviz
docker run -d -p 8787:8787 --name rgeodataviz bhaskarvk/rgeodataviz
Destroying the container (docker container rm
) will delete any data or files you may have changed, so back them up somewhere.
The Tutorial Material
The tutorial material is in two directories inst/presentations
and inst/notebooks
. The presentations
directory contains RMarkdowns used to generate the slides, and the notebooks
directory contains many code samples in R Notebook format for you to play with. You can knit these files directly from withing RStudio.
Slides and R Notebooks
Part 1: Introduction
I will go over the objectives and the scope of the tutorial, introduce myself, get to know the audience a bit. We will also try and solve any last minute setup issues, in case someone has them.
Part 2: R Packages
In this part I will briefly go over some major R packages available for working with spatial data. We will cover R packages for data containers, reading/writing external data, spatial operations, and finally plotting spatial data.
Part 3: Spatial Data
Here we will go over the major R packages for storing spatial data in an R environment. We will also explore briefly some common ways to interact with spatial data stored in files/databases.
Part 4: Spatial Data Operations
Here we will explore some common spatial operations on data. This involves sub-setting, joining spatial data. Determining centroids, convex hulls, voronoi regions etc.
Part 5: Ways to Output Maps
In this section we will explore how to integrate maps in to your documents and applications. We will explore options for print maps in PDFs, to online and/or interactive maps in web pages. We will also explore dynamic mapping using Shiny.
Part 6: Static Maps
Maps that are put in documents, and web pages. Maps than can be printed out. We will explore various mapping techniques, but primarily focused on ggplot2 based techniques.
Part 7: Interactive Maps
Maps meant for the web. Maps that users can interact with and explore in more details. Maps that can be changed dynamically in a Shiny application on user interaction.
In addition to the slides, you can also consult the following R Notebooks for an alternative format. Source code for these notebooks is in the same repo as above under inst/notebooks
directory