Spatial plotting in R

Similar documents
THE UNITED REPUBLIC OF TANZANIA MINISTRY OF WORKS, TRANSPORT AND COMMUNICATION TANZANIA METEOROLOGICAL AGENCY

THE UNITED REPUBLIC OF TANZANIA MINISTRY OF WORKS, TRANSPORT AND COMMUNICATION TANZANIA METEOROLOGICAL AGENCY

THE UNITED REPUBLIC OF TANZANIA 2014/15 ANNUAL AGRICULTURAL SAMPLE SURVEY REPORT

Any progress in the reduction of poverty in South Asia?

How to Develop Master Sampling Frames using Dot Sampling Method and Google Earth

The United Republic of Tanzania

Urbanisation in Tanzania

Spatially Explicit Burden Estimates of Malaria in Tanzania: Bayesian Geostatistical Modeling of the Malaria Indicator Survey Data

URBAN PLANNING STUDY FOR TANZANIA IMPACT AND EFFECTIVENESS OF URBAN PLANNING ON CITY SPATIAL DEVELOPMENT. BACKGROUND PROFILE OF CITIES October 2017

ANALYSIS OF RAINFALL CHARACTERISTICS IN TANZANIA FOR CLIMATE CHANGE SIGNALS'/

Using R for Epidemiological Analysis

Global Atmospheric Circulation Patterns Analyzing TRMM data Background Objectives: Overview of Tasks must read Turn in Step 1.

VALIDATION OF SATELLITE RAINFALL ESTIMATES USING GAUGE RAINFALL OVER TANZANIA MOHAMED MOHAMED HAMIS REGISTRATION NO: I45/84346/2012

THE CLIMATOLOGICAL REGIONS OF TANZANIA BASED ON THE RAINFALL CHARACTERISTICS

Spatial is special. The earth is not flat (coordinate reference systems) Size: lots and lots of it, multivariate, time series

Population growth, internal migration, and urbanisation in Tanzania,

Findings from a Search for R Spatial Analysis Support. Donald L. Schrupp Wildlife Ecologist Colorado Division of Wildlife (Retired)

Public Expenditure Review (In Two Volumes) Volume 2: Statistical Appendix

Groundwater vulnerability to geogenic contaminants: a case study, Tanzania

Visual Studies Exercise, Assignment 07 (Architectural Paleontology) Geographic Information Systems (GIS), Part II

The Choropleth Map Slide #2: Choropleth mapping enumeration units

Practical 12: Geostatistics

What are the five components of a GIS? A typically GIS consists of five elements: - Hardware, Software, Data, People and Procedures (Work Flows)

cor(dataset$measurement1, dataset$measurement2, method= pearson ) cor.test(datavector1, datavector2, method= pearson )

Introduction to GIS I

INTERNATIONAL JOURNAL OF GEOMATICS AND GEOSCIENCES

Working with Digital Elevation Models in ArcGIS 8.3

Developing Database and GIS (First Phase)

Handling Raster Data for Hydrologic Applications

Open Source Geospatial Software - an Introduction Spatial Programming with R

GIS IN ECOLOGY: ANALYZING RASTER DATA

Pioneering Geothermal Development in Tanzania Geothermal Exploration Drilling Activities

Exercise 4 Estimating the effects of sea level rise on coastlines by reclassification

Gis Unit TropMed Mahidol U.

Overlay Analysis II: Using Zonal and Extract Tools to Transfer Raster Values in ArcMap

Package RSwissMaps. October 3, 2017


Analysing Spatial Data in R: Worked example: geostatistics

Creating Watersheds from a DEM

Grid to LandGrid Volumetrics Workflow

10/13/2011. Introduction. Introduction to GPS and GIS Workshop. Schedule. What We Will Cover

Transactions on Information and Communications Technologies vol 18, 1998 WIT Press, ISSN

The Geodatabase Working with Spatial Analyst. Calculating Elevation and Slope Values for Forested Roads, Streams, and Stands.

INTRODUCTION TO GEOGRAPHIC INFORMATION SYSTEM By Reshma H. Patil

Geographers Perspectives on the World

Practical 12: Geostatistics

Data Creation and Editing

Climate variability and satellite observed vegetation responses in Tanzania

Lab 7: Cell, Neighborhood, and Zonal Statistics

Outline Anatomy of ArcGIS Metadata Data Types Vector Raster Conversion Adding Data Navigation Symbolization Methods Layer Files Editing Help Files

INTRODUCTION TO GIS. Practicals Guide. Chinhoyi University of Technology

In this exercise we will learn how to use the analysis tools in ArcGIS with vector and raster data to further examine potential building sites.

GEOFOTO GROUP LTD. Buzinski prilaz 28, Zagreb, Croatia tel.: ,

Lesson Plan 2 - Middle and High School Land Use and Land Cover Introduction. Understanding Land Use and Land Cover using Google Earth

Explore the data. Anja Bråthen Kristoffersen Biomedical Research Group

Overview of the spnet package

Chapter 2 Exploratory Data Analysis

Hot Spot / Point Density Analysis: Kernel Smoothing

Geographical Information Systems

DATA COLLECTION SURVEY ON GEOTHERMAL ENERGY DEVELOPMENT IN EAST AFRICA FINAL REPORT (TANZANIA)

ACKNOWLEDGMENTS. This paper is based on research funded by the Rockefeller Foundation. I would

GeoWEPP Tutorial Appendix

Performing Advanced Cartography with Esri Production Mapping

9-25. Sediment in Massai Steppe. Lake Natron, Lake Eyasi, Lake Manyara, Bahi swamp, part of Bubu river Purple. Purple-red Saline lake, swamp

Watersheds : Spatial watershed aggregation and spatial drainage network analysis

Canadian climate: function-on-function regression

Map image from the Atlas of Oregon (2nd. Ed.), Copyright 2001 University of Oregon Press

Performing Map Cartography. using Esri Production Mapping

REPORT on the KIBARA MINERAL EXPLORATION PROPERTY. of TANZANIAN ROYALTY EXPLORATION CORPORATION. in the BUNDA DISTRICT, MARA REGION

An Assessment of Spatial Integration for Major Wholesale Rice Markets in Tanzania

ISU GIS CENTER S ARCSDE USER'S GUIDE AND DATA CATALOG

Geo 327G Semester Project. Landslide Suitability Assessment of Olympic National Park, WA. Fall Shane Lewis

REPORT on the LUNGUYA MINERAL EXPLORATION PROPERTY. of TANZANIAN ROYALTY EXPLORATION CORPORATION. in the KAHAMA DISTRICT, SHINYANGA REGION

Introduction to ggplot2. ggplot2 is (in my opinion) one of the best documented packages in R. The full documentation for it can be found here:

Analysis of the Sediment Production Characteristics by the Satellite Image - Case Study in Tanzania Hiroshi OGAWA(1), Hiroyuki KATHURO(1),

Tutorial 8 Raster Data Analysis

NATIONAL REPORT TO THE 7 TH SOUTHERN AFRICAN AND ISLANDS HYDROGRAPHIC COMMISSION

Introducing GIS analysis

ENV208/ENV508 Applied GIS. Week 1: What is GIS?

Applied geostatistics Exercise 6 Assessing the quality of spatial predictions Geostatistical simulation

Calhoun County, Texas Under 5 Meter Sea Level Rise

GIS = Geographic Information Systems;

MATH 408N PRACTICE MIDTERM 1

Delineation of Watersheds

Int. J. Biosci Nelson Mandela African Institution of Science and Technology, Arusha, Tanzania

Studying Topography, Orographic Rainfall, and Ecosystems (STORE)

Geographic Information Systems. Introduction to Data and Data Sources

Package Watersheds. R topics documented: February 9, Type Package

Exercise 6: Working with Raster Data in ArcGIS 9.3

Problems and Challenges

Using the Stock Hydrology Tools in ArcGIS

ArcMap - EXPLORING THE DATABASE Part I. SPATIAL DATA FORMATS Part II

BASIC SPATIAL ANALYSIS TOOLS IN A GIS. data set queries basic statistics buffering overlay reclassification

Louisiana Transportation Engineering Conference. Monday, February 12, 2007

The Looming Threat of Rising Sea Levels to the Florida Keys

Learning ArcGIS: Introduction to ArcCatalog 10.1

Explore the data. Anja Bråthen Kristoffersen

Dar es Salaam - Reality Check Workshop

COASTAL MANAGEMENT IN TANZANIA

Laboratorio di ST1 Lezione 4

Transcription:

Spatial plotting in R Contents Introduction................................................. 1 Plotting various spatial objects...................................... 1 2 2 Using plot()............................................. 2 Using spplot()............................................ 9 2 Introduction One of the biggest advantages of working with spatial data is you can easily visualualize the spatial variation of the data. You do it by making maps. Maps are everywhere! In this session, we will focus on making maps using both raster and spatail class data. Like basic plots, for making maps there are number packages and functions available. However, with the following two functions from sp packages a large number of plotting can be done. 1. plot based on base R plotting system 2. spplot based on grid system plot allows incremental addition of graphical elements in a single plotting device; whereas spplot does not allow such addition (similar to lattice or ggplot2). spplot makes maps with shared axes which makes visualization and comparison of multiple maps much easier. Plotting various spatial objects We will plot various raster (elevation) and vector data (administrative boundaries, rivers, lakes and protected areas) of Tanzania. First we will use the plot function. Make sure your working directory is data directory for this specific excercise. Important Some of the vector data is in *.shp file format while others is in *.rds R database format. You can save anykind of data in *.rds format. Use readrds and saverds to read and save data in *.rds format respectively. 1

Using plot() library(raster) #setwd("...") v0 <- readrds('tza_adm0.rds') plot(v0, border = "red") title(main = "Tanzania national boundary", sub = "source GADM") Tanzania national boundary source GADM Ex 1: Fill the polygon using a different color and change increase the thickness of the border 2

Color individual regions We will use the region boundaries from GADM database (level = 1) v1 <- readrds('tza_adm1.rds') # Each region should have different color; we will use the color ramp n <- length(v1$name_1) plot(v1, col=rainbow(n), main = 'Administrative boundary: level 1') # Now add name of the indiviudal regions to the map text(v1, v1$name_1, cex=0.75) Administrative boundary: level 1 Kagera Mara Mwanza Simiyu Geita Shinyanga Arusha Kilimanjaro Kigoma Katavi Rukwa Tabora Mbeya Singida Dodoma Iringa Manyara Morogoro Tanga Pemba North Pemba South Zanzibar North Zanzibar Zanzibar South West and Central Dar es Salaam Pwani Njombe Lindi Ruvuma Mtwara Ex 2: Read and plot level 2 administrative boundaries of Tanzania. Give different colors to the regions. Add SpatialLines object to your plot We will plot the river. 3

rv <- shapefile('tanzania_rivers.shp') plot(v0, border = "red", lwd = 2, axes = TRUE) plot(rv, col='blue', add = TRUE) title(main = "Tanzania rivers") # Add some more details legend('topright', legend = 'River', lty = 1, lwd = 2, col = 'blue', bty = "n") Tanzania rivers 12 S 10 S 8 S 6 S 4 S 2 S River 30 E 32 E 34 E 36 E 38 E 40 E Ex 3. Change the country boundary color, river color and place the legend in the bottom left of the plot. Add additional SpatialPolygons Now we will plot the lake and protected areas of Tanzania. First read the required boundaries. lake <- shapefile('tza_glwd.shp') protarea <- shapefile('tza_wdpa.shp') plot(v0, lwd = 2, axes = TRUE) 4

plot(lake, col='lightblue', border = 'transparent', add = TRUE) plot(protarea, col='lightgreen', border = 'transparent', add = TRUE) title(main = "Tanzania lakes and protected area") Tanzania lakes and protected area 12 S 10 S 8 S 6 S 4 S 2 S 30 E 32 E 34 E 36 E 38 E 40 E Note the border= transparent option suppresses the plotting of polygon borders. Ex 4. Check what happens when you don t use the border argument in while plotting lake and protected areas. Plot Raster We will plot the elevation of Tanzania. alt <- raster('tza_alt.tif') plot(alt, col = terrain.colors(20), axes=false) title(main = "Elevation (in m)") 5

Elevation (in m) 5000 4000 3000 2000 1000 0 To improve the visualization, we can limit the higher and lower elevataion zones. alt[alt < 0] = 0 alt[alt > 3000] = 3000 plot(alt, col = terrain.colors(20), axes=false) title(main = "Elevation (in m)") 6

Elevation (in m) 3000 2500 2000 1500 1000 500 0 Plotting two raster layers We will show elevation and avergae annual temperature in the same plot. temp <- raster('tza_bio1.tif') temp[temp < 0] = 0 par(mfrow=c(1,2)) plot(alt, col = terrain.colors(20), axes=false) title(main = "Elevation (in m)") plot(temp, col = rev(heat.colors(50)), axes=false) title(main ="Annual Mean Temp ( C)") 7

Elevation (in m) Annual Mean Temp ( C) 3000 2500 2000 1500 1000 500 0 25 20 15 10 5 0 Adding Spatial *object to raster We will add the lake, rivers and administrative boundaries to the elevation raster plot plot(alt, col = terrain.colors(20), legend = FALSE) plot(lake, col='skyblue1', border = 'transparent', add = TRUE) plot(rv, col='blue1', add = TRUE) plot(v0, lwd = 2, axes = TRUE, add = TRUE) title(main = "Lakes and rivers of Tanzania") 8

12 10 8 6 4 2 Lakes and rivers of Tanzania 30 32 34 36 38 40 Using spplot() We will use spplot for different plotting applications. # Use soil properties information; Soil organic carbon content and soil ph orc <- raster('tza_orc.tif') ph <- raster('tza_ph.tif') soil <- stack(orc, ph) orc[orc>80]<- 80 spplot(orc, main = list(label="soil organic carbon content", 9 cex = 1))

Soil organic carbon content 80 70 60 50 40 30 20 10 0 # change the ph values between 0 to 14 ph <- ph/10 spplot(ph, main = list(label="soil ph", cex = 1)) 10

Soil ph 8.0 7.5 7.0 6.5 6.0 5.5 5.0 4.5 4.0 Now to change the color ramp and change legend position: brks <- seq(0,60,0.5) spplot(orc, at = round(brks, digits=2), col.regions = rev(terrain.colors(length(brks))), colorkey = list(space = "bottom"), main = list(label="soil organic carbon content", cex = 1)) 11

Soil organic carbon content 0 10 20 30 40 50 60 Ex 5. Make similar changes to ph plot. Hint: the brks will take place at differnt sequence based on ph values Adding Spatial *object to raster We will add the lake and administrative boundary to the elevation raster plot pols <- list("sp.lines", as(v0, 'SpatialLines')) brks <- seq(0,60,0.5) spplot(orc, sp.layout=pols, at = round(brks, digits=2), col.regions = rev(terrain.colors(length(brks))), colorkey = list(space = "bottom"), main = list(label="soil organic carbon content", cex = 1)) 12

Soil organic carbon content 0 10 20 30 40 50 60 See the difference with plot function. There is no use of add=true argument. You can also add multiple SpatialObjects to the plot. pols1 <- list("sp.lines", as(v0, 'SpatialLines'), col = gray(0.4), lwd = 0.5) pols2 <- list("sp.polygons", as(lake, 'SpatialPolygons'), fill = 'skyblue1',col="transparent", first = F brks <- seq(0,60,0.5) spplot(orc, sp.layout=list(pols1, pols2), at = round(brks, digits=2), col.regions = rev(terrain.colors(length(brks))), colorkey = list(space = "bottom"), main = list(label="soil organic carbon content", cex = 1)) 13

Soil organic carbon content 0 10 20 30 40 50 60 Ex 6. Add the protected area boundaries to the plot. Donot fill the protected area polygon with any color. Plot multiband raster object You can also use ssplot to plot multiband raster brks <- seq(0,70,0.5) ph <- ph*10 soil <- stack(orc,ph) spplot(soil, layout = c(2,1), at = round(brks, digits=2), col.regions = rev(terrain.colors(length(brks))), colorkey = list(space = "bottom"), main = list(label="soil properties", cex = 1)) 14

Soil properties TZA_ORC TZA_PH 0 10 20 30 40 50 60 70 Ex 7.* Save your favorite plot using the following: png(filename = "your-favorite-plot", width = 250, height = 200, units = "mm", res = 300) plot... spplot... dev.off() 15