Advanced Spatial Methods in R

Slides:



Advertisements
Similar presentations
EziLink RESULTS Training Session 1 – Show and Tell For the Ministry of Forests, Lands and Natural Resource Operations.
Advertisements

EZpak Office Clipart Starter Kit for Clinical Packaging office.ezpak.net.
Writing functions in R Some handy advice for creating your own functions.
Content-Based Image Retrieval
NSF DUE ; Module 4.3. NSF DUE ; GeoTEd Partners Module name and number.
Geoprocessing; Useful Tools You Should Know in ArcToolbox Unlock the hidden secrets of ArcToolbox to discover tools that make your work easier and analysis.
Templates and Styles Excel Advanced. Templates are pre- designed and formatted spreadsheets –They provide consistency of layout/structure –They.
Intro to GGMAP Emmalee Dolfi. Ethical Implications of Spatial Analysis  Spatially displaying data can change how it’s interpreted  Locational privacy.
GIS for Environmental Science
High Quality Maps With R and ggplot
Unit One: GIS Concepts In this unit… ► What is GIS? ► Types of GIS data ► What can you do with GIS? ► ArcGIS 9 license levels ► Basics of the ArcGIS 9.
Visualizing Multiple Physician Office Locations Exercise 9 GIS in Planning and Public Health Wansoo Im, Ph.D.
NR 322: Single Layer Analysis Jim Graham Fall 2008 Chapter 8 & 9.
Building Our Capacities to Write in the Public Interest Agenda for 3/17/09 & 3/19/09.
SuperPad 3 Full-Function Mobile GIS Software. Overview  SuperPad, full-function mobile GIS software, is designed for field survey and data collection.
Law Enforcement Resource Allocation (LERA) Visualization System Michael Welsman-Dinelle April Webster.
Spatial Analysis, Geoprocessing,
Quick maps in R Melanie Frazier, NCEAS Presentation materials here:
Introduction to the Use of Geographic Information Systems in Public Health Elio Spinello, MPH California State University, Northridge.
Intro. To GIS Lecture 6 Spatial Analysis April 8th, 2013
Rebecca Boger Earth and Environmental Sciences Brooklyn College.
Fundamentals of GIS Lecture Materials by Austin Troy except where noted © 2008 Lecture 13: Introduction to Raster Spatial Analysis Using GIS-- By.
Integrating Microsoft Project with Other Programs
Chapter 4 Dreamweaver: Part II The Web Warrior Guide to Web Design Technologies.
A Sample Print Web Service Utilizing ArcGIS Server and ArcObjects Cheryl Spencer, IndyGIS Marianne Cardwell, Woolpert.
AN INTRODUCTION TO GRAPHICS IN R. Today Overview Overview –Gallery of R Graph examples High-Level Plotting Functions High-Level Plotting Functions Low-Level.
Concept demo System dashboard. Overview Dashboard use case General implementation ideas Use of MULE integration platform Collection Aggregation/Factorization.
1 1 ISyE 6203 Radical Tools Intro To GIS: MapPoint John H. Vande Vate Spring 2012.
Ranjeet Department of Physics & Astrophysics University of Delhi Working with Origin.
Using ArcView to Create a Transit Need Index John Babcock GRG394 Final Presentation.
Enabling High-Quality Printing in Web Applications
An Internet of Things: People, Processes, and Products in the Spotfire Cloud Library Dr. Brand Niemann Director and Senior Data Scientist/Data Journalist.
Synopsys Custom Designer Tutorial for a chip integration using the University of Utah Standard Cell Libraries In ON Semiconductor 0.5u C5 CMOS Version.
HS115 Unit 7 Seminar December 22, 2010 David Rudnick, Instructor.
McGraw-Hill Career Education© 2008 by the McGraw-Hill Companies, Inc. All Rights Reserved. Office Excel 2007 Lab 2 Charting Worksheet Data.
NR 143 Study Overview: part 1 By Austin Troy University of Vermont Using GIS-- Introduction to GIS.
General review & continuation of Chapter 2 computer lab efforts tom.h.wilson Department of Geology and Geography West Virginia.
Ggplot2 A cool way for creating plots in R Maria Novosolov.
INTRODUCTION TO GIS  Used to describe computer facilities which are used to handle data referenced to the spatial domain.  Has the ability to inter-
O LLIVIER & C O New Zealand Projections Projections Workshop Basic Projection Steps NZ Transverse Mercator Projections in ArcGIS 8.2 Reprojecting Images.
Intermacs Form Download Excel Tutorial Pivot Tables, Graphic Tools, Macros By: Devin Koehl.
Data Analytics CMIS Short Course part II Day 1 Part 1: Introduction Sam Buttrey December 2015.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
Lecture 11 Introduction to R and Accessing USGS Data from Web Services Jeffery S. Horsburgh Hydroinformatics Fall 2013 This work was funded by National.
Especially created for ASL faculty. By Gloria Barron.
Geocoding Chapter 16 GISV431 &GEN405 Dr W Britz. Georeferencing, Transformations and Geocoding Georeferencing is the aligning of geographic data to a.
Geocoding Chapter 16 GISV431 &GEN405 Dr W Britz. Georeferencing, Transformations and Geocoding Georeferencing is the aligning of geographic data to a.
# install.packages( "RCurl" ) # install RCurl if you have not done this already library( RCurl ) # package to read data from html files # copy the download.
Geospatial Data Abstraction Library(GDAL) Sabya Sachi.
Block 1: Introduction to R
Date Topic Presenter Aug. 25 Intro to Visualization Michael Boyles
Overview of R and ggplot2 for graphics
Lecture 2: Introduction to R
Designing a Spatial/GIS Project
INTRODUCTION TO GEOGRAPHICAL INFORMATION SYSTEM
The Commute: The Battle of Finding Distance
Summary Statistics in R Commander
Gimp Guide Mr Hall.
Introduction to MATLAB
Welcome to E-Prime E-Prime refers to the Experimenter’s Prime (best) development studio for the creation of computerized behavioral research. E-Prime is.
Electronic Field Study Advanced User Training
Raster Data Analysis.
Overview of R and ggplot2 for graphics
Simulation And Modeling
Exploring Microsoft® Office 2016 Series Editor Mary Anne Poatsy
Using Veera with R and Shiny to Build Complex Visualizations
What's New in eCognition 9
The Data of Visualization
GeoPlanner: Site Suitability Analysis
Presentation transcript:

Advanced Spatial Methods in R Michael Mann George Washington University Department of Geography mmann1123@gwu.edu http://michaelmann.i234.me/

Overview Review Basics Setting up Space-time data Space-time plots library(RasterVis) library(plotKML) Vector & Other Data Visualization library(ggplot2) Mapping ggplot2 visualizations library(ggmap)

Before we begin Best places for help http://stackoverflow.com/ Question & Answer form. Quick & high quality responses ?function_name Look up help files for a function from any library http://gis.stackexchange.com/ Similar to stackoverflow, but targeted to spatial community The fridge – grab a beer and spend some time

Interpreting My Slides! Inputs into command line Outputs Notes Data is in the MMSpatialData folder s = c("aa", "bb", "cc", "dd", "ee") s [1] "aa” "bb” "cc” "dd” "ee" An important note

Your location Quick survey Please raise you hand if (before today) you have never used R or a similar language.

Let’s even the playing field Beginners Please look around you. Move if there is a beginner cluster! Experts Put on your teaching hats! Remember how difficult this material is. Make sure to help your teammates!

Overview Indexing a vector Indexing a data.frame Helpful Functions s = c("aa", "bb", "cc", "dd", "ee") s = data.frame(col1=c(1,2,3), col2=c(5,6,7)) s[1] s[c(2,5)] col1 col2 1 1 5 2 2 6 3 3 7 [1] ‘aa’ [1] ‘bb’ ‘ee’ s[2,1] s[,’col2’] s[c(2:5)] [1] 2 [1] 5 6 7 [1] ‘bb’ ‘cc’ ‘dd’ ‘ee’ vector_name[ position_# ] vector_name[ row#, col# ]

Objective 1 – Raster space-time plots library(raster) Raster Stacks & Bricks Multidimensional raster objects Multi-layer (red,green,blue) Multi-dim (time series, multi variable) Indexing Your Data stack[row# ,col#, Z#] Y Z X

Objective 1 – Raster space-time plots Multi-layer Raster ‘Brick’ b <- brick(system.file("external/rlogo.grd", package="raster) plot(b) Brick[X,Y,Z]

Objective 1 – Raster space-time plots Multi-layer Raster Brick plotRGB(b, r=1, g=2, b=3)

Objective 1 – Raster space-time plots Multi-dimentional Raster Stack Good for time-series of rasters, or multivariate analysis Time Series Multivariate stack[x,y, c(cwd2000-2010) ] stack[x,y, c(crime,pop) ]

Objective 1 – Raster space-time plots Multi-dimentional Raster Stack Good for time-series of rasters, or multivariate analysis Time Series Multivariate stack[x,y, c(cwd2000-2010) ] stack[x,y, c(crime,pop) ] Use: Data Visualization Use: Regression Analysis, modeling

Task 1.1 – Setup Raster Stack Data Helpful Functions dir() grep() dir(‘C://SESYNC//data’) grep(‘a’, c( ‘a’, ‘b’, ‘c’, ‘a’ ) ) [1] 1 4 grep(‘c’, c( ‘tab’, ‘car’, ‘bat’ ) ) [1] 2 [1] ‘data.zip’ ‘ggmap vinette.pdf’….

Task 1.1 – Setup Raster Stack Data Helpful Functions – Using grep to index a vector Find the location of a element with ‘c’ in it Query vector s with the grep s = c("aa", "bb", "cc", "dd", "ee") grep(‘c’, s ) [1] 3 s[ grep(‘c’, s ) ] [1] ‘cc’

Task 1.1 – Setup Raster Stack Data Helpful Functions – Using grep to index a vector Find the location of a element with ‘c’ in it Query vector s with the grep s = c("aa", "bb", "cc", "dd", "ee") grep(‘c’, s ) [1] 3 TRY THIS! s[ grep(‘c’, s ) ] [1] ‘cc’

Task 1.1 – Let’s get started!

Task 1.2 – Create Raster Stacks and Assign Name Labels Helpful Functions paste() names() paste(‘Hi',c('Bill','Bob', 'Sam'), sep=' ') names(rstack) = c(‘test2001’,’test2002’) [1] “Hi Bill" “Hi Bob" “Hi Sam" paste(’aet',c(’2001',’2002’), sep=’_') [1] "aet_2001" "aet_2002" test2002 test2001

Task 1.2 – Create Raster Stacks and Assign Name Labels Helpful Functions paste() names() paste(‘Hi',c('Bill','Bob', 'Sam'), sep=' ') names(rstack) = c(‘test2001’,’test2002’) [1] “Hi Bill" “Hi Bob" “Hi Sam" TRY PASTE()! paste(’aet',c(’2001',’2002’), sep=’_') [1] "aet_2001" "aet_2002" test2002 test2001

Task 1.2 – Create Raster Stacks and Assign Time Labels Helpful Functions seq() & as.Date() setz() seq(1,15, by=3) raster_stack = setZ(raster_stack, years) [1] 1 4 7 10 13 Years = seq(as.Date(’2001-01-01'), as.Date('2010-01-01'), by=’1 year') [1] "2000-01-01" "2001-01-01" … [10] "2009-01-01" "2010-01-01"

Task 1.2 – Create Raster Stacks and Assign Time Labels Helpful Functions seq() & as.Date() setz() seq(1,15, by=3) raster_stack = setZ(raster_stack, years) [1] 1 4 7 10 13 Important: setZ must be passed a series of ‘Dates’ (created with as.Date function) Years = seq(as.Date(’2001-01-01'), as.Date('2010-01-01'), by=’1 year') [1] "2000-01-01" "2001-01-01" … [10] "2009-01-01" "2010-01-01"

Task 1.2 – Let’s get started!

Task 1.3 – Visualize Stack Data Indexing Your Data Method 1 plot(raster_stack[[1]]) # plot first raster plot(raster_stack[[2]]) # plot second raster NOTE: [[ ]] is used b/c stack is a list object Method 2 plot( raster(raster_stack,'HDen_1989') ) NOTE: raster() is used b/c… well that is just how it works

Task 1.3 – Let’s get started!

Task 1.4 – Challenge Questions

Task 1.5 Visualize Space-Time Data rasterVis & plotKML packages Excellent tutorial available at http://rastervis.r-forge.r-project.org/ Data Format Raster stack with z-dim set to dates using: as.Date() Spatial points or polygons data.frame with z-dim set to dates Hovmoller Plot Horizon Plot

Task 1.5 Visualize Space-Time Data rasterVis & plotKML packages Data Format 2 Raster stack OR Spatial points or polygons data.frame with z-dim set to slope, or direction Vectorplot Stream Plot

Task 1.5 Visualize Space-Time Data rasterVis & plotKML packages Excellent tutorial: http://plotkml.r-forge.r-project.org/ Data Format Exports many formats including raster stacks Note: This code outputs both a Housing.kml file and a series of other image files (.png files). In order for this to work, the Housing.kml file needs to be in the same directory as all the image files.

Task 1.5 Visualize Space-Time Data rasterVis & plotKML packages Excellent tutorial: http://plotkml.r-forge.r-project.org/ Data Format Exports many formats including raster stacks All data must be unprojected Lat Lon "+proj=longlat +datum=WGS84” Note: This code outputs both a Housing.kml file and a series of other image files (.png files). In order for this to work, the Housing.kml file needs to be in the same directory as all the image files.

Task 1.5 – Let’s get started!

Task 1.6 – Let’s get started!

Objective 2: Intro to ggplot2 One of the best data visualization tools in R Documentation available here: http://ggplot2.org/

Objective 2: Intro to ggplot2 A plot is made up of multiple layers. A layer consists of data, a set of mappings between variables and aesthetics, a geometric object and a statistical transformation Scales control the details of the mapping. All components are independent and reusable.

Objective 2: Intro to ggplot2 aesthetics geometric object scales control ‘+’ add mappings Typical Command a = ggplot(movies, aes(y = budget, x = year, group = round_any(year, 10) )) + geom_boxplot() + scale_y_log10() plot(a)

Task 2.1 Setting up your data ggplot2 uses data.frames!

Task 2.1 Setting up your data Helpful Functions aggregate() Summarizes data of interest by factors (categorical data) aggregate( rating ~ year ,data= movies, FUN='mean')

Task 2.1 Setting up your data Helpful Functions fortify() Converts spatial polygons, lines, points to data.frame usable in ggplot2 jepson.points = fortify(jepson, region="id")

Task 2.1 Let’s get going!

Objective 2: Intro to ggplot2 plot reminder aesthetics geometric object scales control ‘+’ add mappings Typical Command a = ggplot(jepson.df) + aes(long,lat,group=group,fill=ECOREGION) + geom_polygon() plot(a)

Task 2.2 Let’s get going!

Task 2.3 Let’s get going!

Task 2.4 Challenge questions

Objective 3: Intro to ggmap Ggmap enables visualization of layered graphics using implementation similar to ggplot2 Combines the functionality of ggplot2 and spatial information of static maps from Google Maps, OpenStreetMap, Stamen Maps or CloudMade

Objective 3: Intro to ggmap Ggmap enables visualization of layered graphics using implementation similar to ggplot2 qmap() Downloads static maps from google, or OSM Defined by a central Lat and Lon and a ‘Zoom’ level Takes additional ‘+’ commands to overlay ggplot2 graphics Zoom = 5 Zoom = 14

Objective 3: Intro to ggmap plot aesthetics geometric object scales control coordinate system Done in background through qmap ‘+’ add mappings Typical Command HoustonMap <- qmap("houston", zoom = 13, color = "bw") HoustonMap + geom_point(data=violent_crimes,aes(x = lon, y = lat, colour = offense ) ) plot( HoustonMap )

Task 3.1 Setting up your data Helpful Functions projectRaster() & project() Converts spatial -polygons, -lines, -points to data.frame usable in ggplot2 & ggmap. Ggmap data must be in unprojected lat lon (defined below) # Project a raster to unprojected Lat Lon using nearest neighbor algorithm stack_proj = projectRaster(raster_stack, crs="+proj=longlat +datum=WGS84” , method='ngb') # Project a polygon to unprojected Lat Lon using nearest neighbor algorithm jepson_proj = project(jepson, crs="+proj=longlat +datum=WGS84”)

Task 3.1 Setting up your data Helpful Functions fortify() Converts spatial polygons, lines, points to data.frame usable in ggplot2 jepson.points = fortify(jepson, region="id")

Task 3.1 Setting up your data Helpful Functions geocode() revgeocode() Converts text addresses or location names to Lat Lon coordindates Converts Lat Lon to text addresses geocode("the white house") revgeocode(c(-77.03650, 38.89768), output = c("address"))

Task 3.1 Setting up your data Helpful Functions subset() data = data.frame(name=c(‘mike’,’john’,’jim’), age=c(4,3,6)) name age mike 4 john 3 jim 6 name age 2 john 3 3 jim 6 subset(data, name != ‘mike’ ) name age 1 mike 4 3 jim 6 subset(data, age > 3 )

Task 3.1: Learn Basic ggmap Functions

Task 3.2: Crime Mapping In Houston TX

Task 3.3: Challenge Questions

What should we review?