Analysing Spatial Data in R: Vizualising Spatial Data

Similar documents
Analysing Spatial Data in R: Representing Spatial Data

Package Grid2Polygons

Visualising Spatial Data UCL Geography R Spatial Workshop Tuesday 9 th November 2010 rspatialtips.org.uk

Module 10. Data Visualization. Andrew Jaffe Instructor

SISMID Spatial Statistics in Epidemiology and Public Health 2015 R Notes: Introduction

Advanced Multivariate Continuous Displays and Diagnostics

Package automap. May 30, 2011

Data Visualization. Andrew Jaffe Instructor

Lab 1 Introduction to R

Applied Statistics : Practical 11

plot(seq(0,10,1), seq(0,10,1), main = "the Title", xlim=c(1,20), ylim=c(1,20), col="darkblue");

Key Terms. Symbology. Categorical attributes. Style. Layer file

Raman Spectra of Chondrocytes in Cartilage: hyperspec s chondro data set

Introduction to using R for Spatial Analysis

Package r2d2. February 20, 2015

Practical 11: Interpolating Point Data in R

Introduction to Geospatial Analysis

Logical operators: R provides an extensive list of logical operators. These include

Using Spatial Data in a Desktop GIS; QGIS 2.8 Practical 2

DSCI 325: Handout 18 Introduction to Graphics in R

Announcements. Data Sources a list of data files and their sources, an example of what I am looking for:

Geographic Information Systems. using QGIS

Watershed Sciences 4930 & 6920 GEOGRAPHIC INFORMATION SYSTEMS

Plotting Complex Figures Using R. Simon Andrews v

Exploratory Data Analysis - Part 2 September 8, 2005

Tutorial 1 Exploring ArcGIS

Watershed Sciences 4930 & 6920 ADVANCED GIS

Map overlay and spatial aggregation in sp

An introduction to ggplot: An implementation of the grammar of graphics in R

Examples of implementation of pre-processing method described in paper with R code snippets - Electronic Supplementary Information (ESI)

GGR 375 QGIS Tutorial

Package smoothr. April 4, 2018

Package hextri. April 22, 2016

In math, the rate of change is called the slope and is often described by the ratio rise

Terms and definitions * keep definitions of processes and terms that may be useful for tests, assignments

layers in a raster model

Using R as a GIS. Alan R. Pearse. 31 July 2017

Types of Plotting Functions. Managing graphics devices. Further High-level Plotting Functions. The plot() Function

Map overlay and spatial aggregation in sp

Technology Assignment: Scatter Plots

QGIS LAB SERIES GST 102: Spatial Analysis Lab 2: Introduction to Geospatial Analysis

This document will cover some of the key features available only in SMS Advanced, including:

Applied Calculus. Lab 1: An Introduction to R

Package sciplot. February 15, 2013

Package desplot. R topics documented: April 3, 2018

Package arphit. March 28, 2019

SAS Visual Analytics 8.2: Getting Started with Reports

2. Getting started with MLwiN

Package beanplot. R topics documented: February 19, Type Package

Roger D. Peng, Associate Professor of Biostatistics Johns Hopkins Bloomberg School of Public Health

A quick Matlab tutorial

AN INTRODUCTION TO LATTICE GRAPHICS IN R

rworldmap vignette Andy South October 5, 2012

Charts in Excel 2003

Geography 222 Quantitative Color for GIS Mike Pesses, Antelope Valley College

ArcGIS Online (AGOL) Quick Start Guide Fall 2018

1 Layering, and Alternatives to Layering

Package ClustGeo. R topics documented: July 14, Type Package

Basic Queries Exercise - Haiti

2013 edition (version 1.1)

Lab 1: Introduction to ArcGIS

Raman Spectra of Chondrocytes in Cartilage: hyperspec s chondro data set

Lecture-14 Lookup Functions

GIS LAB 8. Raster Data Applications Watershed Delineation

From Getting Started with the Graph Template Language in SAS. Full book available for purchase here.

Practical guidance on mapping and visualisation of crime and social data in QGIS

Profiles - Objectives

Mixed models in R using the lme4 package Part 2: Lattice graphics

Mapping Great Circles Tutorial

Intro to R Graphics Center for Social Science Computation and Research, 2010 Stephanie Lee, Dept of Sociology, University of Washington

Package fso. February 19, 2015

Spatial Data Models. Raster uses individual cells in a matrix, or grid, format to represent real world entities

Performance Evaluation

Spatial data and QGIS

Intro to GIS (requirements: basic Windows computer skills and a flash drive)

ArcView QuickStart Guide. Contents. The ArcView Screen. Elements of an ArcView Project. Creating an ArcView Project. Adding Themes to Views

Lab #4 Introduction to Image Processing II and Map Accuracy Assessment

Stat 579: Objects in R Vectors

Package EnQuireR. R topics documented: February 19, Type Package Title A package dedicated to questionnaires Version 0.

_Tutorials. Arcmap. Linking additional files outside from Geodata

An Introduction to R Graphics

Leading provider of interactive statistics visualization software for the web

Complete Display Control in Autodesk Architectural Desktop

Introduction to using R for Spatial Analysis Nick Bearman

Package osrm. November 13, 2017

Geography 281 Map Making with GIS Project Three: Viewing Data Spatially

Nearest Neighbor Predictors

AN INTRODUCTION TO GRID ANALYSIS: HOTSPOT DETECTION

lab_03 September 20, 2016

Data Classification 1

An Introduction to R 2.2 Statistical graphics

R Workshop Module 3: Plotting Data Katherine Thompson Department of Statistics, University of Kentucky

ggplot2 basics Hadley Wickham Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University September 2011

Package spark. July 21, 2017

Lecturer 2: Spatial Concepts and Data Models

Package mixphm. July 23, 2015

Chapter 5 An Introduction to Basic Plotting Tools

MAPLOGIC CORPORATION. GIS Software Solutions. Getting Started. With MapLogic Layout Manager

Graphics - Part III: Basic Graphics Continued

Representing the Real World

Transcription:

Analysing Spatial Data in R: Vizualising Spatial Data Roger Bivand Department of Economics Norwegian School of Economics and Business Administration Bergen, Norway 31 August 2007

Vizualising Spatial Data Displaying spatial data is one of the chief reasons for providing ways of handling it in a statistical environment Of course, there will be differences between analytical and presentation graphics here as well the main point is to get a usable display quickly, and move to presentation quality cartography later In general, maintaining aspect is vital, and that can be done in both base and lattice graphics in R (note that both sp and maps display methods for spatial data with geographical coordinates stretch the y-axis) We ll look at the basic methods for displaying spatial data in sp; other packages have their own methods, but the next unit will show ways of moving data from them to sp classes

Just spatial objects There are base graphics plot methods for the key Spatial* classes, including the Spatial class, which just sets up the axes In base graphics, additional plots can be added by overplotting as usual, and the locator() and identify() functions work as expected In general, most par() options will also work, as will the full range of graphics devices (although some copying operations may disturb aspect) First we will display the positional data of the objects discussed in the first unit

Plotting a SpatialPoints object 330000 331000 332000 333000 179000 180000 181000 While plotting the SpatialPoints object would have called the plot method for Spatial objects internally to set up the axes, we start by doing it separately: > plot(as(meuse1, "Spatial"), + axes = TRUE) > plot(meuse1, add = TRUE) > plot(meuse1[meuse1$ffreq == + 1, ], col = "green", add = TRUE) Then we plot the points with the default plotting character, and subset, overplotting points in flood frequency class 1 in green, using the [ method

Plotting a SpatialPolygons object 330000 331000 332000 333000 334000 In plotting the SpatialPolygons object, we use the ylim= argument to restrict the display area to match the soil sample points. > plot(rivers, axes = TRUE, col = "azure1", + ylim = c(329400, 334000)) > box() If the axes= argument is FALSE or omitted, no axes are shown the default is the opposite from standard base graphics plot methods 178000 179000 180000 181000 182000

Plotting a SpatialPixels object 330000 331000 332000 333000 334000 Both SpatialPixels and SpatialGrid objects are plotted like SpatialPoints objects, with plotting characters > plot(rivers, axes = TRUE, col = "azure1", + ylim = c(329400, 334000)) > box() > plot(meuseg1, add = TRUE, col = "grey60", + cex = 0.15) While points, lines, and polygons are often plotted without attributes, this is rarely the case for gridded objects 178000 179000 180000 181000 182000

Including attributes To include attribute values means making choices about how to represent their values graphically, known in some GIS as symbology It involves choices of symbol shape, colour and size, and of which objects to differentiate When the data are categorical, the choices are given, unless there are so many different categories that reclassification is needed for clear display Once we ve looked at some examples, we ll go on to see how class intervals may be chosen for continuous data

Flood frequencies at soil sample sites annual every 2 5 years > 5 years We will usually need to get the category levels and match them to colours (or plotting characters) by hand > meuse1$ffreq1 <- as.numeric(meuse1$ffreq) > plot(meuse1, col = meuse1$ffreq1, + pch = 19) > labs <- c("annual", "every 2-5 years", + "> 5 years") > cols <- 1:nlevels(meuse1$ffreq) > legend("topleft", legend = labs, + col = cols, pch = 19, bty = "n") It is also typical that the legend() involves more code than everything else together, but very often the same vectors are used repeatedly and can be assigned just once

Coloured contour lines Here again, the values are represented as a categorical variable, and so do not require classification > volcano_sl$level1 <- as.numeric(volcano_sl$level) > pal <- terrain.colors(nlevels(volcano_sl$level)) > plot(volcano_sl, bg = "grey70", + col = pal[volcano_sl$level1], + lwd = 3) Using class membership for colour palette look-up is a very typical idiom, so that the col= argument is in fact a vector of colour values

Displaying gridded data annual every 2 5 years > 5 years Since we also have 40m grid flood frequencies, we can try to display them here we use the image() method, which first fills in the NAs, the makes a matrix of the chosen variable > meuseg1$ffreq1 <- as.numeric(meuseg1$ffreq) > image(meuseg1, "ffreq1", col = cols) > legend("topleft", legend = labs, + fill = cols, bty = "n") Some of the arguments here are like those we ll meet soon for lattice graphics

Class intervals Class intervals can be chosen in many ways, and some have been collected for convenience in the classint package The first problem is to assign class boundaries to values in a single dimension, for which many classification techniques may be used, including pretty, quantile, natural breaks among others, or even simple fixed values From there, the intervals can be used to generate colours from a colour palette, using the very nice colorramppalette() function Because there are potentially many alternative class memberships even for a given number of classes (by default from nclass.sturges), choosing a communicative set matters

Class intervals We will try just two styles, quantiles and Fisher-Jenks natural breaks for five classes, among the many available. They yield quite different impressions, as we will see: > library(classint) > library(rcolorbrewer) > pal <- brewer.pal(3, "Blues") > q5 <- classintervals(meuse1$zinc, n = 5, style = "quantile") > q5 style: quantile one of 14,891,626 possible partitions of this variable into 5 classes under 186.8 186.8-246.4 246.4-439.6 439.6-737.2 over 737.2 31 31 31 31 31 > fj5 <- classintervals(meuse1$zinc, n = 5, style = "fisher") > fj5 style: fisher one of 14,891,626 possible partitions of this variable into 5 classes under 307.5 307.5-573.0 573.0-869.5 869.5-1286.5 75 32 29 12 over 1286.5 7 > plot(q5, pal = pal) > plot(fj5, pal = pal)

Class interval plots Quantile Fisher Jenks natural breaks 0.0 0.2 0.4 0.6 0.8 1.0 0.0 0.2 0.4 0.6 0.8 1.0 0 500 1000 1500 2000 0 500 1000 1500 2000

Two versions of zinc ppm Quantile under 186.8 186.8 246.4 246.4 439.6 439.6 737.2 over 737.2 Fisher Jenks natural breaks under 307.5 307.5 573.0 573.0 869.5 869.5 1286.5 over 1286.5

Lattice graphics Lattice graphics will only come into their own later on, when we want to plot several variables with the same scale together for comparison The workhorse method is spplot, which can be used as an interface to the underlying xyplot or levelplot methods, or others as suitable; overplotting must be done in the single call to spplot see gallery It is often worthwhile to load the lattice package so as to have direct access to its facilities Please remember that lattice graphics are displayed on the current graphics device by default only in interactive sessions in loops or functions, they must be explicitly print ed

Bubble plots zinc 100 200 400 800 1600 Bubble plots are a convenient way of representing the attribute values by the size of a symbol > library(lattice) > bubble(meuse1, "zinc", maxsize = 2, + key.entries = 100 * 2^(0:4)) As with all lattice graphics objects, the function can return an object from which symbol sizes can be recovered

Level plots 1.0 0.8 0.6 0.4 0.2 The use of lattice plotting methods yields easy legend generation, which is another attraction > bpal <- colorramppalette(pal)(41) > spplot(meuseg1, "dist", col.regions = bpal, + cuts = 40) Here we are showing the distances from the river of grid points in the study area; we can also pass in intervals chosen previously 0.0

More realism So far we have just used canned data and spatial objects rather than anything richer The vizualisation methods are also quite flexible both the base graphics and lattice graphics methods can be extensively customised It is also worth recalling the range of methods available for sp objects, in particular the overlay and spsample methods with a range of argument signatures These can permit further flexibility in display, in addition to their primary uses