+ - 0:00:00
Notes for current slide
Notes for next slide

R for geographic map: Session 2

Manipulate a raster data in R

1

DAAD climapAfrica - Climate change research in Africa

©Francisco Maiato Gonçalves

2

Contents

  • Definition of a raster data
  • Utility of a raster data
  • Hands on session
4

What is a raster data?

5

What is a raster data?

©National Ecological Observatory Network (NEON)

6

Resolution matters

©National Ecological Observatory Network (NEON)

7

You say multi-band raster data?

©National Ecological Observatory Network (NEON)

8

Why store data as a raster?

9

Why store data as a raster?

The advantages of storing your data as a raster are as follows:

  • A simple data structure—A matrix of cells with values representing a coordinate and sometimes linked to an attribute table

  • A powerful format for advanced spatial and statistical analysis

  • The ability to represent continuous surfaces and perform surface analysis

  • The ability to uniformly store points, lines, polygons, and surfaces

  • The ability to perform fast overlays with complex datasets

©ArcGIS

10

Why store data as a raster?

  • There can be spatial inaccuracies due to the limits imposed by the raster dataset cell dimensions

  • Raster datasets are potentially very large. Resolution increases as the size of the cell decreases

  • However, normally cost also increases in both disk space and processing speeds. For a given area, changing cells to one-half the current size requires as much as four times the storage space, depending on the type of data and storage techniques used.

©ArcGIS

11

Applications of raster data

12

Applications of raster data

Raster data are frequently used in diverse domains including:

  • species distribution modeling;

  • rainfall variability over time;

  • forest distribution and/or coverage;

  • water supply availability;

  • agricultural landscape;

  • land distribution;

  • vegetation studies;

  • wild animal tracking and management.

©Raes & Aguirre‐Gutiérrez 2018 | John Wiley & Sons Ldt

13

Hands on session

Packages loading

library(ggplot2)
library(raster)
library(tidyr)
library(rnaturalearth)
library(rgeos)
library(cowplot)
14

Data acquisition

climate = getData('worldclim', var = 'bio', res = 2.5)
15

See the data

plot(climate)
raster-map1
16

Crop the data to the African continent

climate = crop(climate, extent(-20, 60, -40, 40))
17

Check the data

plot(climate)
raster-map2
18

Get the raster 12 relative to the rainfall

raster_rainfall = climate$bio12

Get countries borders shapefiles from the package rnaturalearth

africa = rnaturalearth::ne_countries(continent = 'africa', returnclass = 'sf')
19

Plot it

plot(africa)
raster-map3
20

Raster data conversion into dataframe

rasdf = as.data.frame(raster_rainfall, xy = TRUE)%>%drop_na()

Check it

head(rasdf)
## x y bio12
## 1 -8.937500 39.97917 838
## 2 -8.895833 39.97917 856
## 3 -8.854167 39.97917 863
## 4 -8.812500 39.97917 882
## 5 -8.770833 39.97917 888
## 6 -8.729167 39.97917 872
21

Plotting

m = ggplot() +
geom_tile(aes(x=x, y=y, fill=bio12), data = rasdf) +
geom_sf(fill = 'transparent', data = africa) +
scale_fill_viridis_c(name= 'mm/yr', direction = -1 ) +
labs(x= 'Longitute' , y = 'Latitude',
title = "Africa's climate map",
subtitle = "Annual precipitation",
caption = 'Source: WordClim, 2020') +
cowplot::theme_cowplot() +
theme(panel.grid.major = element_line(color = "black",
linetype = 'dashed',
size = .5),
panel.grid.minor = element_blank(),
panel.ontop = TRUE,
panel.background = element_rect(fill = NA, color = 'black'))
22

Should get this

<raster-map4
23

Your turn.....Thanks!

24

DAAD climapAfrica - Climate change research in Africa

©Francisco Maiato Gonçalves

2
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow