Amoud University
Amoud University

Abstract

This course on Spatial Analysis with R provides participants with a comprehensive introduction to spatial analysis techniques using the R programming language. Participants will learn how to analyze different types of spatial data, including areal data, point patterns, and geostatistical datasets, and gain insights into spatial patterns, relationships, and variations. The course emphasizes reproducible research practices and covers topics such as data manipulation, visualization, spatial interpolation, clustering, regression, and modeling. By the end of the course, participants will have the skills and knowledge to conduct spatial analysis, document their workflows, and apply spatial analysis techniques to real-world problems in various fields.

Module I: Introduction to Spatial Analysis

Introduction

Spatial analysis is a powerful tool that enables us to understand, interpret, and derive meaningful insights from spatial data. It plays a crucial role in a wide range of disciplines, including geography, environmental sciences, urban planning, epidemiology, and social sciences. By examining the spatial patterns, relationships, and distributions of various phenomena, spatial analysis provides valuable information for decision-making, problem-solving, and policy development.

Spatial analysis involves the application of analytical techniques to spatially referenced data, where the geographic location or spatial context of the data is fundamental to the analysis. It goes beyond traditional data analysis methods by incorporating spatial relationships and considering the influence of location on the observed phenomena. This unique perspective allows for a deeper understanding of how spatial factors impact various processes and phenomena.

The field of spatial analysis encompasses a diverse set of techniques and approaches, including spatial data manipulation, spatial interpolation, spatial clustering, spatial regression, and spatial modeling. These techniques enable researchers and analysts to explore spatial patterns, identify trends, detect hotspots, predict future occurrences, and assess the impact of spatial factors on different phenomena.

One of the key advantages of spatial analysis is its ability to reveal hidden insights and connections that may not be apparent through traditional analytical methods. By integrating spatial data with other forms of data, such as socio-economic variables or environmental data, researchers can uncover spatial relationships and identify potential causal factors driving observed patterns.

Furthermore, advances in technology and the availability of geospatial data have significantly expanded the scope and applications of spatial analysis. Geographic Information Systems (GIS) and remote sensing technologies have revolutionized the collection, management, and analysis of spatial data, providing researchers with powerful tools to explore and visualize spatial information.

In this era of big data and rapid urbanization, spatial analysis has become increasingly important for addressing complex spatial problems and informing evidence-based decision-making. From understanding the spread of diseases to optimizing transportation networks, spatial analysis has the potential to revolutionize how we perceive, analyze, and respond to spatially related challenges.

This primer aims to provide a comprehensive introduction to spatial analysis techniques using the R programming language, with a focus on reproducible research practices. It will guide readers through the fundamental concepts of spatial analysis, various spatial analysis techniques, and the importance of reproducibility in spatial research. By the end of this primer, readers will have the knowledge and skills to conduct spatial analysis, uncover spatial patterns, and derive meaningful insights from spatial data using R.

Spatial analysis opens up a world of possibilities for understanding and harnessing the power of spatial information. Whether it is for academic research, urban planning, environmental management, or public health, spatial analysis offers a valuable toolkit for exploring the complex interplay between space, phenomena, and human activities, ultimately leading to informed decision-making and sustainable development.

Types of Spatial Data

Spatial data can be classified into three main types: areal data, point patterns, and geostatistical datasets. Each type represents a different spatial arrangement and provides unique insights into spatial phenomena. Here’s an overview of these types along with real-life examples and their common applications:

Areal Data:

Areal data, also known as areal unit data or areal datasets, represent spatial information aggregated at predefined areal units such as administrative boundaries, census tracts, or grid cells. This type of data assigns values or attributes to specific geographic areas. Examples of areal data include population density by census tract, average income by administrative region, or land cover classification by grid cell.

Real-life Example: Areal data is commonly used in socio-economic analysis and regional planning. For instance, city planners may use areal data on population density to identify areas of high population growth and plan infrastructure development accordingly. Similarly, policymakers may use average income data by administrative region to assess income disparities and allocate resources for social welfare programs.

Point Patterns:

Point pattern data refers to spatial data that represents individual point locations in a geographic space. These points can represent events, occurrences, or observations. Point pattern datasets are used to analyze the spatial distribution, clustering, and patterns of events or phenomena.

Real-life Example: Point pattern data finds applications in various fields. For instance, in epidemiology, the locations of disease outbreaks can be represented as point patterns to identify spatial clusters and understand the spread of diseases. Similarly, crime analysts use point pattern data to study crime hotspots and allocate resources for effective policing strategies.

Geostatistical Datasets:

Geostatistical datasets, also known as continuous spatial data, are characterized by values that are measured or estimated at multiple locations across a continuous geographic space. Unlike areal data and point patterns, geostatistical datasets provide information at every location within the study area.

Real-life Example: Geostatistical datasets are widely used in environmental sciences, geology, and natural resource management. For instance, meteorologists use geostatistical datasets of temperature measurements at weather stations to create temperature maps and understand regional climate patterns. Geologists may collect geostatistical data on soil properties to model soil contamination levels across a contaminated site.

Understanding the different types of spatial data and their applications is crucial for selecting appropriate analysis techniques and interpreting the results accurately. Whether analyzing areal data, point patterns, or geostatistical datasets, spatial analysis provides valuable insights into the spatial relationships, patterns, and variations of phenomena, contributing to informed decision-making and better understanding of the world around us.

Maps

Countries

# Course Spatial Analysis
# Lecture I: Spatial Data Types
# 1. Maps for Countries
library(maptools)
## Warning: package 'maptools' was built under R version 4.1.3
## Loading required package: sp
## Warning: package 'sp' was built under R version 4.1.3
## Checking rgeos availability: TRUE
## Please note that 'maptools' will be retired by the end of 2023,
## plan transition at your earliest convenience;
## some functionality will be moved to 'sp'.
# Load the wrld_simple dataset
data(wrld_simpl)

# Extract a specific country from the dataset (e.g., Somalia)
somalia <- wrld_simpl[wrld_simpl$NAME == "Somalia", ]

plot(somalia)

# Plot the boundaries of Somalia
plot(somalia, border = "black", col = "lightblue", 
     main = "Areal Data: Administrative 
     Boundaries of Somalia")

countries<-wrld_simpl$NAME
countries
##   [1] Antigua and Barbuda                      
##   [2] Algeria                                  
##   [3] Azerbaijan                               
##   [4] Albania                                  
##   [5] Armenia                                  
##   [6] Angola                                   
##   [7] American Samoa                           
##   [8] Argentina                                
##   [9] Australia                                
##  [10] Bahrain                                  
##  [11] Barbados                                 
##  [12] Bermuda                                  
##  [13] Bahamas                                  
##  [14] Bangladesh                               
##  [15] Belize                                   
##  [16] Bosnia and Herzegovina                   
##  [17] Bolivia                                  
##  [18] Burma                                    
##  [19] Benin                                    
##  [20] Solomon Islands                          
##  [21] Brazil                                   
##  [22] Bulgaria                                 
##  [23] Brunei Darussalam                        
##  [24] Canada                                   
##  [25] Cambodia                                 
##  [26] Sri Lanka                                
##  [27] Congo                                    
##  [28] Democratic Republic of the Congo         
##  [29] Burundi                                  
##  [30] China                                    
##  [31] Afghanistan                              
##  [32] Bhutan                                   
##  [33] Chile                                    
##  [34] Cayman Islands                           
##  [35] Cameroon                                 
##  [36] Chad                                     
##  [37] Comoros                                  
##  [38] Colombia                                 
##  [39] Costa Rica                               
##  [40] Central African Republic                 
##  [41] Cuba                                     
##  [42] Cape Verde                               
##  [43] Cook Islands                             
##  [44] Cyprus                                   
##  [45] Denmark                                  
##  [46] Djibouti                                 
##  [47] Dominica                                 
##  [48] Dominican Republic                       
##  [49] Ecuador                                  
##  [50] Egypt                                    
##  [51] Ireland                                  
##  [52] Equatorial Guinea                        
##  [53] Estonia                                  
##  [54] Eritrea                                  
##  [55] El Salvador                              
##  [56] Ethiopia                                 
##  [57] Austria                                  
##  [58] Czech Republic                           
##  [59] French Guiana                            
##  [60] Finland                                  
##  [61] Fiji                                     
##  [62] Falkland Islands (Malvinas)              
##  [63] Micronesia, Federated States of          
##  [64] French Polynesia                         
##  [65] France                                   
##  [66] Gambia                                   
##  [67] Gabon                                    
##  [68] Georgia                                  
##  [69] Ghana                                    
##  [70] Grenada                                  
##  [71] Greenland                                
##  [72] Germany                                  
##  [73] Guam                                     
##  [74] Greece                                   
##  [75] Guatemala                                
##  [76] Guinea                                   
##  [77] Guyana                                   
##  [78] Haiti                                    
##  [79] Honduras                                 
##  [80] Croatia                                  
##  [81] Hungary                                  
##  [82] Iceland                                  
##  [83] India                                    
##  [84] Iran (Islamic Republic of)               
##  [85] Israel                                   
##  [86] Italy                                    
##  [87] Cote d'Ivoire                            
##  [88] Iraq                                     
##  [89] Japan                                    
##  [90] Jamaica                                  
##  [91] Jordan                                   
##  [92] Kenya                                    
##  [93] Kyrgyzstan                               
##  [94] Korea, Democratic People's Republic of   
##  [95] Kiribati                                 
##  [96] Korea, Republic of                       
##  [97] Kuwait                                   
##  [98] Kazakhstan                               
##  [99] Lao People's Democratic Republic         
## [100] Lebanon                                  
## [101] Latvia                                   
## [102] Belarus                                  
## [103] Lithuania                                
## [104] Liberia                                  
## [105] Slovakia                                 
## [106] Liechtenstein                            
## [107] Libyan Arab Jamahiriya                   
## [108] Madagascar                               
## [109] Martinique                               
## [110] Mongolia                                 
## [111] Montserrat                               
## [112] The former Yugoslav Republic of Macedonia
## [113] Mali                                     
## [114] Morocco                                  
## [115] Mauritius                                
## [116] Mauritania                               
## [117] Malta                                    
## [118] Oman                                     
## [119] Maldives                                 
## [120] Mexico                                   
## [121] Malaysia                                 
## [122] Mozambique                               
## [123] Malawi                                   
## [124] New Caledonia                            
## [125] Niue                                     
## [126] Niger                                    
## [127] Aruba                                    
## [128] Anguilla                                 
## [129] Belgium                                  
## [130] Hong Kong                                
## [131] Northern Mariana Islands                 
## [132] Faroe Islands                            
## [133] Andorra                                  
## [134] Gibraltar                                
## [135] Isle of Man                              
## [136] Luxembourg                               
## [137] Macau                                    
## [138] Monaco                                   
## [139] Palestine                                
## [140] Montenegro                               
## [141] Mayotte                                  
## [142] Aaland Islands                           
## [143] Norfolk Island                           
## [144] Cocos (Keeling) Islands                  
## [145] Antarctica                               
## [146] Bouvet Island                            
## [147] French Southern and Antarctic Lands      
## [148] Heard Island and McDonald Islands        
## [149] British Indian Ocean Territory           
## [150] Christmas Island                         
## [151] United States Minor Outlying Islands     
## [152] Vanuatu                                  
## [153] Nigeria                                  
## [154] Netherlands                              
## [155] Norway                                   
## [156] Nepal                                    
## [157] Nauru                                    
## [158] Suriname                                 
## [159] Nicaragua                                
## [160] New Zealand                              
## [161] Paraguay                                 
## [162] Peru                                     
## [163] Pakistan                                 
## [164] Poland                                   
## [165] Panama                                   
## [166] Portugal                                 
## [167] Papua New Guinea                         
## [168] Guinea-Bissau                            
## [169] Qatar                                    
## [170] Reunion                                  
## [171] Romania                                  
## [172] Republic of Moldova                      
## [173] Philippines                              
## [174] Puerto Rico                              
## [175] Russia                                   
## [176] Rwanda                                   
## [177] Saudi Arabia                             
## [178] Saint Kitts and Nevis                    
## [179] Seychelles                               
## [180] South Africa                             
## [181] Lesotho                                  
## [182] Botswana                                 
## [183] Senegal                                  
## [184] Slovenia                                 
## [185] Sierra Leone                             
## [186] Singapore                                
## [187] Somalia                                  
## [188] Spain                                    
## [189] Saint Lucia                              
## [190] Sudan                                    
## [191] Sweden                                   
## [192] Syrian Arab Republic                     
## [193] Switzerland                              
## [194] Trinidad and Tobago                      
## [195] Thailand                                 
## [196] Tajikistan                               
## [197] Tokelau                                  
## [198] Tonga                                    
## [199] Togo                                     
## [200] Sao Tome and Principe                    
## [201] Tunisia                                  
## [202] Turkey                                   
## [203] Tuvalu                                   
## [204] Turkmenistan                             
## [205] United Republic of Tanzania              
## [206] Uganda                                   
## [207] United Kingdom                           
## [208] Ukraine                                  
## [209] United States                            
## [210] Burkina Faso                             
## [211] Uruguay                                  
## [212] Uzbekistan                               
## [213] Saint Vincent and the Grenadines         
## [214] Venezuela                                
## [215] British Virgin Islands                   
## [216] Viet Nam                                 
## [217] United States Virgin Islands             
## [218] Namibia                                  
## [219] Wallis and Futuna Islands                
## [220] Samoa                                    
## [221] Swaziland                                
## [222] Yemen                                    
## [223] Zambia                                   
## [224] Zimbabwe                                 
## [225] Indonesia                                
## [226] Guadeloupe                               
## [227] Netherlands Antilles                     
## [228] United Arab Emirates                     
## [229] Timor-Leste                              
## [230] Pitcairn Islands                         
## [231] Palau                                    
## [232] Marshall Islands                         
## [233] Saint Pierre and Miquelon                
## [234] Saint Helena                             
## [235] San Marino                               
## [236] Turks and Caicos Islands                 
## [237] Western Sahara                           
## [238] Serbia                                   
## [239] Holy See (Vatican City)                  
## [240] Svalbard                                 
## [241] Saint Martin                             
## [242] Saint Barthelemy                         
## [243] Guernsey                                 
## [244] Jersey                                   
## [245] South Georgia South Sandwich Islands     
## [246] Taiwan                                   
## 246 Levels: Aaland Islands Afghanistan Albania Algeria ... Zimbabwe
Yemen <-wrld_simpl[wrld_simpl$NAME=="Yemen",]
plot(Yemen)

plot(Yemen,border="red",col="green",main="Areal Data: Yemen")

Djibouti <-wrld_simpl[wrld_simpl$NAME=="Djibouti",]
plot(Djibouti)

plot(Djibouti,border="black",col="cyan",main="Djibouti")

Somalia

library(raster) #Load the Raster Library
## Warning: package 'raster' was built under R version 4.1.3
library(geodata)##Load the geodata Library
## Warning: package 'geodata' was built under R version 4.1.3
## Loading required package: terra
## Warning: package 'terra' was built under R version 4.1.3
## terra 1.6.7
Somalia<-getData('GADM', country='SO', level=1)  ##Get the Province Shapefile for Somalia
## Warning in getData("GADM", country = "SO", level = 1): getData will be removed in a future version of raster
## . Please use the geodata package instead
plot(Somalia)                                     ##Plot this shapefile

# Plot Somalia with region names
windows()
plot(Somalia)
text(Somalia, labels = Somalia$NAME_1, col = "black", cex = 0.8)

Somalia: Regions with Colours

# Load necessary libraries
library(raster)
library(geodata)

# Get the Province Shapefile for Somalia
Somalia <- getData('GADM', country = 'SO', level = 1)
## Warning in getData("GADM", country = "SO", level = 1): getData will be removed in a future version of raster
## . Please use the geodata package instead
# Define a color palette for the regions
region_colors <- rainbow(length(Somalia$NAME_1))

# Plot Somalia with colored regions
windows()
plot(Somalia, col = region_colors)
text(Somalia, labels = Somalia$NAME_1, col = "black", cex = 0.8)

Somalia: Assigning Regions with Values

# Load necessary libraries
library(raster)
library(geodata)

# Get the Province Shapefile for Somalia
Somalia <- getData('GADM', country = 'SO', level = 1)
## Warning in getData("GADM", country = "SO", level = 1): getData will be removed in a future version of raster
## . Please use the geodata package instead
# Create example data with values or percentages for each region
region_data <- data.frame(
  Region = Somalia$NAME_1,
  Value = c(1:18)
)

# Merge the region data with the Somalia shapefile
Somalia_data <- merge(Somalia, region_data, by.x = "NAME_1", by.y = "Region")

# Define a color palette for the regions
region_colors <- rainbow(length(Somalia$NAME_1))

# Plot Somalia with colored regions and values or percentages
plot(Somalia_data, col = region_colors)
text(Somalia_data, labels = paste0(Somalia_data$Value, " units"), col = "black", cex = 0.8)

Somalia : Districts

library(raster) #Load the Raster Library
library(geodata)##Load the geodata Library
Somalia<-getData('GADM', country='SO', level=2)  ##Get the Province Shapefile for Somalia
## Warning in getData("GADM", country = "SO", level = 2): getData will be removed in a future version of raster
## . Please use the geodata package instead
plot(Somalia)                                     ##Plot this shapefile

# Plot Somalia with region names
windows()
plot(Somalia)
text(Somalia, labels = Somalia$NAME_2, col = "black", cex = 0.8)

Somalia Districts with Colours

# Load necessary libraries
library(raster)
library(geodata)

# Get the Province Shapefile for Somalia
Somalia <- getData('GADM', country = 'SO', level = 2)
## Warning in getData("GADM", country = "SO", level = 2): getData will be removed in a future version of raster
## . Please use the geodata package instead
# Define a color palette for the regions
region_colors <- rainbow(length(Somalia$NAME_1))

# Plot Somalia with colored regions
windows()
plot(Somalia, col = region_colors)
text(Somalia, labels = Somalia$NAME_2, col = "black", cex = 0.8)

Somaliland

# Load necessary libraries
library(raster)
library(geodata)

# Get the Province Shapefile for Somalia
Somalia <- getData('GADM', country = 'SO', level = 1)
## Warning in getData("GADM", country = "SO", level = 1): getData will be removed in a future version of raster
## . Please use the geodata package instead
# Define the regions you want to select
selected_regions <- c("Awdal", "Woqooyi Galbeed", "Togdheer","Sool","Sanaag")  # Replace with the regions you want

# Subset the Somalia data to include only the selected regions
selected_Somalia <- Somalia[Somalia$NAME_1 %in% selected_regions, ]

# Define a color palette for the regions
region_colors <- rainbow(length(selected_Somalia$NAME_1))

# Plot the selected regions of Somalia with colored regions
windows()
plot(selected_Somalia, col = region_colors)
text(selected_Somalia, labels = selected_Somalia$NAME_1, col = "black", cex = 0.8)

Awdal Region

# Load necessary libraries
library(raster)
library(geodata)

# Get the District Shapefile for Somalia
Somalia <- getData('GADM', country = 'SO', level = 2)
## Warning in getData("GADM", country = "SO", level = 2): getData will be removed in a future version of raster
## . Please use the geodata package instead
# Define the districts you want to select
selected_districts <- c("Zeylac", "Lughaya", "Boorama","Baki")  # Replace with the districts you want

# Subset the Somalia data to include only the selected districts
selected_Somalia <- Somalia[Somalia$NAME_2 %in% selected_districts, ]

# Define a color palette for the districts
district_colors <- rainbow(length(selected_Somalia$NAME_2))

# Plot the selected districts of Somalia with colored regions
windows()
plot(selected_Somalia, col = district_colors)
text(selected_Somalia, labels = selected_Somalia$NAME_2, col = "black", cex = 0.8)

HomeWork 1

  1. Plot the Map of Ethiopia and indicate its geographic regions
  2. Plot the map of Somali region in Ethiopia
  3. Plot the Map of Puntland as they claimed
  4. Plot the Map of Togdheer and indicate its districts
Thanks for your attention
Thanks for your attention