SlideShare ist ein Scribd-Unternehmen logo
1 von 46
Downloaden Sie, um offline zu lesen
Essentials of a
Bas Kempen
© ISRIC-World Soil Information, 2017. Reproduction or dissemination of the work as a whole or parts is not permitted without
consent of the author. Sale or placement on a website where payment must be made to access the document is strictly prohibited. https://creativecommons.org/licenses/by-nc-nd/4.0/
What is R?
• R is a free software environment for statistical computing and
graphics
• R provides a wide variety of statistical (linear and nonlinear
modelling, classical statistical tests, time-series analysis,
classification, clustering, …) and graphical techniques, and is highly
extensible.
– Base functionality (comes with R installation)
– Extension via ‘Packages’ (~6,700)
• www.r-project.org/
• www.r-tutor.com
Why R?
• It is free
• It runs on a variety of platforms
• Platform for (advanced) statistical data analyses
• State-of-the-art graphic capabilities
• Connects with other software (SAGA GIS, GE, Python)
• Very large user community on the web; lots of resources
• R has a steep learning curve
• Thousands of packages, not always easy to find what you are
looking for
• Sometimes cryptic error messages
• Not a GIS
Working with R
RStudio
First steps.....
• Tell R where to find and save your files: setting the
working directory using the ‘setwd’ command:
– setwd(“D:/Bas/SpringSchool/Rintro/workingdir”)
– setwd(“D:BasSpringSchoolRintroworkingdir”)
• Load packages that are required for your analyses:
– library(gstat)
– require(gstat)
(packages should be installed on your computer)
• Note: R is case-sensitive!
Setting up your session
R scripts and data objects
• R scripts are saved as “<name>.R” files
• R objects in the environment can be saved for future
use.
• Save the entire environment or only a couple of
objects.
• Objects are saved as “<name>.rda” or
“<name>.RDATA” files
Basic Data Types
• Numeric
• Integer
• Logical
• Character
• Factor
Vector
Function
Vectors
• Sequence of data elements of the same basic
type.
• Vectors can be combined.
Vector arithmetic
• Vectorized operations: most operations work on vectors with
the same syntax as they work on scalars (no need for looping)
• Vector arithmetic:
• Recycling of vector elements:
Other data structures
• Matrices
• Lists
• Data frames
• Data frame is the fundamental data structure
for statistical modelling in R.
• Data frame is a table with columns and rows
(fields and records).
Data frame
• Columns can have different data types
(numeric, integer, logical, character, factor)
• All columns must have the same length
Selecting subsets
• Selection is done with ‘[...]’
• Vector:
• Data frame:
Functions
• Data analyses and modelling is done through functions.
• These can be very simple:
• More complex functions have multiple arguments (inputs)
• Arguments have specific requirements
• Access help: ?fit.variogram
Plotting
• Large number of packages and functions for
generating plots with basic functionality to
‘high-level’: e.g. lattice and ggplot.
• The basic function for plotting is ‘plot’
ggplot (http://ggplot2.org/)
• library(ggplot2)
• Build your plot layer by layer
• Building blocks:
– geom: the geometric object that describes the
type of plot that is produced.
– aes: ‘aesthetics’, defines the visual properties of
the variables that are going to be plotted.
– scales: control the legend, plot layout
Plotting with ggplot
Plotting with ggplot
Plotting with ggplot
Plotting with ggplot
Importing data
• Importing from tables:
– csv: read.csv()
– txt: read.table()
– xlxs: read.xlsx() [requires package ‘xlsx’]
• Data is imported as a data.frame
Exporting data
• Variety of exporting formats for tabular data:
• Saving plots
Working with spatial data in R
Spatial Data in R
• R offers a wide variety of packages and tools that
can handle spatial data.
• Note: R is not a GIS.
• R is not so memory efficient.
• Relevant packages:
– sp: handling spatial data
– raster: reading/manipulating/writing spatial raster
data
– rgdal: reading/writing spatial data
– maptools: reading/manipulating/writing spatial
polygon data (not maintained anymore)
Spatial data classes and formats
• Vector: points, lines and polygons (areal).
• For storing data that has discrete boundaries, such as
country borders, land parcels, and streets.
• Format: shapefile
Spatial data classes and formats
• Raster: surface divided into a regular grid of cells.
• For storing data that varies continuously, as in a
satellite image, a surface of chemical concentrations,
or an elevation surface.
• Format: GeoTiff (allows embedding spatial reference
information, metadata and color legends. It also
supports internal compression)
• (Ascii, ESRI Grid)
Structures for spatial data
• Spatial data is nothing more than a data frame
that has columns with X and Y coordinates.
• Example:
• Let’s now take a look at R classes for spatial data
(sp package)
Spatial data classes I
• Convert a data frame to a SpatialPointsDataFrame
object with the coordinates function.
Spatial data classes I
• Data frame with data points at regular
intervals.
Spatial data classes II
• Create a grid object with the gridded function:
SpatialPixelsDataFrame
Spatial data classes III
• Create a full grid object with the fullgrid function:
SpatialGridDataFrame
Spatial data classes IV
• The sp class for polygon data is the
SpatialPolygonsDataFrame.
Spatial data classes VI
• The raster package comes with its own class
for raster data: RasterLayer.
Importing spatial data
• rgdal: readOGR (vector), readGDAL (raster)
• maptools: readShapePoly, readShapePoints,
readShapeLines (functions not maintained anymore)
• raster: raster
Projections
• Once you have loaded your spatial data in R,
you have to tell R its geographic projection.
• Check the current projection: proj4string
function.
• Setting a projection: CRS function.
• Reprojecting to another coordinate system:
spTransform function.
Projections
Projections
Plotting
• sp package: spplot
Plotting
ggplot I
ggplot II
ggplot III
Interactive maps
• Interactive maps can be generated with the
leaflet package.
Exporting spatial data
• rgdal: writeOGR (vector), writeGDAL (raster)
• maptools: writePolyShape, writePointsShape
• raster: writeRaster
Now lets practice. Have fun!!

Weitere ähnliche Inhalte

Was ist angesagt?

All python data_analyst_r_course
All python data_analyst_r_courseAll python data_analyst_r_course
All python data_analyst_r_courseKamal A
 
Why R? A Brief Introduction to the Open Source Statistics Platform
Why R? A Brief Introduction to the Open Source Statistics PlatformWhy R? A Brief Introduction to the Open Source Statistics Platform
Why R? A Brief Introduction to the Open Source Statistics PlatformSyracuse University
 
Introduction to R Language
Introduction to R LanguageIntroduction to R Language
Introduction to R LanguageVisuality
 
The TileDB Array Data Storage Manager - Stavros Papadopoulos, Jake Bolewski
The TileDB Array Data Storage Manager - Stavros Papadopoulos, Jake BolewskiThe TileDB Array Data Storage Manager - Stavros Papadopoulos, Jake Bolewski
The TileDB Array Data Storage Manager - Stavros Papadopoulos, Jake BolewskiPyData
 
R data structures-2
R data structures-2R data structures-2
R data structures-2Victor Ordu
 
Apache Spark — Fundamentals and MLlib
Apache Spark — Fundamentals and MLlibApache Spark — Fundamentals and MLlib
Apache Spark — Fundamentals and MLlibJens Fisseler, Dr.
 
R programming language
R programming languageR programming language
R programming languageKeerti Verma
 
Lec_5_Intro to Attributes
Lec_5_Intro to AttributesLec_5_Intro to Attributes
Lec_5_Intro to AttributesAtiqa khan
 
A seminar on neo4 j
A seminar on neo4 jA seminar on neo4 j
A seminar on neo4 jRishikese MR
 
A brief introduction to 'R' statistical package
A brief introduction to 'R' statistical packageA brief introduction to 'R' statistical package
A brief introduction to 'R' statistical packageShanmukha S. Potti
 
2020 Vision (Dubious Design Decisions)
2020 Vision (Dubious Design Decisions)2020 Vision (Dubious Design Decisions)
2020 Vision (Dubious Design Decisions)Alex Henderson
 
DE Presentation v2
DE Presentation v2DE Presentation v2
DE Presentation v2scstark
 
LDBC 8th TUC Meeting: Introduction and status update
LDBC 8th TUC Meeting: Introduction and status updateLDBC 8th TUC Meeting: Introduction and status update
LDBC 8th TUC Meeting: Introduction and status updateLDBC council
 

Was ist angesagt? (20)

All python data_analyst_r_course
All python data_analyst_r_courseAll python data_analyst_r_course
All python data_analyst_r_course
 
Why R? A Brief Introduction to the Open Source Statistics Platform
Why R? A Brief Introduction to the Open Source Statistics PlatformWhy R? A Brief Introduction to the Open Source Statistics Platform
Why R? A Brief Introduction to the Open Source Statistics Platform
 
Introduction to R Language
Introduction to R LanguageIntroduction to R Language
Introduction to R Language
 
The TileDB Array Data Storage Manager - Stavros Papadopoulos, Jake Bolewski
The TileDB Array Data Storage Manager - Stavros Papadopoulos, Jake BolewskiThe TileDB Array Data Storage Manager - Stavros Papadopoulos, Jake Bolewski
The TileDB Array Data Storage Manager - Stavros Papadopoulos, Jake Bolewski
 
Pandas
PandasPandas
Pandas
 
Working with Scientific Data in MATLAB
Working with Scientific Data in MATLABWorking with Scientific Data in MATLAB
Working with Scientific Data in MATLAB
 
TileDB
TileDBTileDB
TileDB
 
R data structures-2
R data structures-2R data structures-2
R data structures-2
 
SPD and KEA: HDF5 based file formats for Earth Observation
SPD and KEA: HDF5 based file formats for Earth ObservationSPD and KEA: HDF5 based file formats for Earth Observation
SPD and KEA: HDF5 based file formats for Earth Observation
 
Apache Spark — Fundamentals and MLlib
Apache Spark — Fundamentals and MLlibApache Spark — Fundamentals and MLlib
Apache Spark — Fundamentals and MLlib
 
R programming language
R programming languageR programming language
R programming language
 
Lec_5_Intro to Attributes
Lec_5_Intro to AttributesLec_5_Intro to Attributes
Lec_5_Intro to Attributes
 
Pilot Project for HDF5 Metadata Structures for SWOT
Pilot Project for HDF5 Metadata Structures for SWOTPilot Project for HDF5 Metadata Structures for SWOT
Pilot Project for HDF5 Metadata Structures for SWOT
 
A seminar on neo4 j
A seminar on neo4 jA seminar on neo4 j
A seminar on neo4 j
 
A brief introduction to 'R' statistical package
A brief introduction to 'R' statistical packageA brief introduction to 'R' statistical package
A brief introduction to 'R' statistical package
 
Hadoop intro
Hadoop introHadoop intro
Hadoop intro
 
2020 Vision (Dubious Design Decisions)
2020 Vision (Dubious Design Decisions)2020 Vision (Dubious Design Decisions)
2020 Vision (Dubious Design Decisions)
 
DE Presentation v2
DE Presentation v2DE Presentation v2
DE Presentation v2
 
LDBC 8th TUC Meeting: Introduction and status update
LDBC 8th TUC Meeting: Introduction and status updateLDBC 8th TUC Meeting: Introduction and status update
LDBC 8th TUC Meeting: Introduction and status update
 
Working with HDF and netCDF Data in ArcGIS: Tools and Case Studies
Working with HDF and netCDF Data in ArcGIS: Tools and Case StudiesWorking with HDF and netCDF Data in ArcGIS: Tools and Case Studies
Working with HDF and netCDF Data in ArcGIS: Tools and Case Studies
 

Ähnlich wie Essentials of R

Data Analytics with R and SQL Server
Data Analytics with R and SQL ServerData Analytics with R and SQL Server
Data Analytics with R and SQL ServerStéphane Fréchette
 
Arc gis introduction-ppt
Arc gis introduction-pptArc gis introduction-ppt
Arc gis introduction-pptAshok Peddi
 
Apdm 101 Arc Gis Pipeline Data Model (1)
Apdm 101 Arc Gis Pipeline Data Model  (1)Apdm 101 Arc Gis Pipeline Data Model  (1)
Apdm 101 Arc Gis Pipeline Data Model (1)David Nichter, GISP
 
Big data analytics with R tool.pptx
Big data analytics with R tool.pptxBig data analytics with R tool.pptx
Big data analytics with R tool.pptxsalutiontechnology
 
Materi Geodatabase Management - Fellowship 2022.pdf
Materi Geodatabase Management - Fellowship 2022.pdfMateri Geodatabase Management - Fellowship 2022.pdf
Materi Geodatabase Management - Fellowship 2022.pdfsakinatunnajmi
 
Advanced Data Analytics with R Programming.ppt
Advanced Data Analytics with R Programming.pptAdvanced Data Analytics with R Programming.ppt
Advanced Data Analytics with R Programming.pptAnshika865276
 
How to obtain and install R.ppt
How to obtain and install R.pptHow to obtain and install R.ppt
How to obtain and install R.pptrajalakshmi5921
 
Slides on introduction to R by ArinBasu MD
Slides on introduction to R by ArinBasu MDSlides on introduction to R by ArinBasu MD
Slides on introduction to R by ArinBasu MDSonaCharles2
 
Introduction to R _IMPORTANT FOR DATA ANALYTICS
Introduction to R _IMPORTANT FOR DATA ANALYTICSIntroduction to R _IMPORTANT FOR DATA ANALYTICS
Introduction to R _IMPORTANT FOR DATA ANALYTICSHaritikaChhatwal1
 
R programming groundup-basic-section-i
R programming groundup-basic-section-iR programming groundup-basic-section-i
R programming groundup-basic-section-iDr. Awase Khirni Syed
 
Introduction to R for data science
Introduction to R for data scienceIntroduction to R for data science
Introduction to R for data scienceLong Nguyen
 
Analytics Beyond RAM Capacity using R
Analytics Beyond RAM Capacity using RAnalytics Beyond RAM Capacity using R
Analytics Beyond RAM Capacity using RAlex Palamides
 
Week-3 – System RSupplemental material1Recap •.docx
Week-3 – System RSupplemental material1Recap •.docxWeek-3 – System RSupplemental material1Recap •.docx
Week-3 – System RSupplemental material1Recap •.docxhelzerpatrina
 
Using R to Visualize Spatial Data: R as GIS - Guy Lansley
Using R to Visualize Spatial Data: R as GIS - Guy LansleyUsing R to Visualize Spatial Data: R as GIS - Guy Lansley
Using R to Visualize Spatial Data: R as GIS - Guy LansleyGuy Lansley
 
UNIT - III GIS DATA STRUCTURES (2).ppt
UNIT - III GIS DATA STRUCTURES (2).pptUNIT - III GIS DATA STRUCTURES (2).ppt
UNIT - III GIS DATA STRUCTURES (2).pptRamMishra65
 

Ähnlich wie Essentials of R (20)

Data Analytics with R and SQL Server
Data Analytics with R and SQL ServerData Analytics with R and SQL Server
Data Analytics with R and SQL Server
 
Arc gis introduction-ppt
Arc gis introduction-pptArc gis introduction-ppt
Arc gis introduction-ppt
 
Apdm 101 Arc Gis Pipeline Data Model (1)
Apdm 101 Arc Gis Pipeline Data Model  (1)Apdm 101 Arc Gis Pipeline Data Model  (1)
Apdm 101 Arc Gis Pipeline Data Model (1)
 
Big data analytics with R tool.pptx
Big data analytics with R tool.pptxBig data analytics with R tool.pptx
Big data analytics with R tool.pptx
 
Materi Geodatabase Management - Fellowship 2022.pdf
Materi Geodatabase Management - Fellowship 2022.pdfMateri Geodatabase Management - Fellowship 2022.pdf
Materi Geodatabase Management - Fellowship 2022.pdf
 
Advanced Data Analytics with R Programming.ppt
Advanced Data Analytics with R Programming.pptAdvanced Data Analytics with R Programming.ppt
Advanced Data Analytics with R Programming.ppt
 
design_doc
design_docdesign_doc
design_doc
 
How to obtain and install R.ppt
How to obtain and install R.pptHow to obtain and install R.ppt
How to obtain and install R.ppt
 
17641.ppt
17641.ppt17641.ppt
17641.ppt
 
Slides on introduction to R by ArinBasu MD
Slides on introduction to R by ArinBasu MDSlides on introduction to R by ArinBasu MD
Slides on introduction to R by ArinBasu MD
 
17641.ppt
17641.ppt17641.ppt
17641.ppt
 
Introduction to R _IMPORTANT FOR DATA ANALYTICS
Introduction to R _IMPORTANT FOR DATA ANALYTICSIntroduction to R _IMPORTANT FOR DATA ANALYTICS
Introduction to R _IMPORTANT FOR DATA ANALYTICS
 
R programming groundup-basic-section-i
R programming groundup-basic-section-iR programming groundup-basic-section-i
R programming groundup-basic-section-i
 
Introduction to R for data science
Introduction to R for data scienceIntroduction to R for data science
Introduction to R for data science
 
Analytics Beyond RAM Capacity using R
Analytics Beyond RAM Capacity using RAnalytics Beyond RAM Capacity using R
Analytics Beyond RAM Capacity using R
 
Week-3 – System RSupplemental material1Recap •.docx
Week-3 – System RSupplemental material1Recap •.docxWeek-3 – System RSupplemental material1Recap •.docx
Week-3 – System RSupplemental material1Recap •.docx
 
Step By Step Guide to Learn R
Step By Step Guide to Learn RStep By Step Guide to Learn R
Step By Step Guide to Learn R
 
Using R to Visualize Spatial Data: R as GIS - Guy Lansley
Using R to Visualize Spatial Data: R as GIS - Guy LansleyUsing R to Visualize Spatial Data: R as GIS - Guy Lansley
Using R to Visualize Spatial Data: R as GIS - Guy Lansley
 
محاضرة برنامج التحليل الكمي R program د.هديل القفيدي
محاضرة برنامج التحليل الكمي   R program د.هديل القفيديمحاضرة برنامج التحليل الكمي   R program د.هديل القفيدي
محاضرة برنامج التحليل الكمي R program د.هديل القفيدي
 
UNIT - III GIS DATA STRUCTURES (2).ppt
UNIT - III GIS DATA STRUCTURES (2).pptUNIT - III GIS DATA STRUCTURES (2).ppt
UNIT - III GIS DATA STRUCTURES (2).ppt
 

Mehr von ExternalEvents

Mehr von ExternalEvents (20)

Mauritania
Mauritania Mauritania
Mauritania
 
Malawi - M. Munthali
Malawi - M. MunthaliMalawi - M. Munthali
Malawi - M. Munthali
 
Malawi (Mbewe)
Malawi (Mbewe)Malawi (Mbewe)
Malawi (Mbewe)
 
Malawi (Desideri)
Malawi (Desideri)Malawi (Desideri)
Malawi (Desideri)
 
Lesotho
LesothoLesotho
Lesotho
 
Kenya
KenyaKenya
Kenya
 
ICRAF: Soil-plant spectral diagnostics laboratory
ICRAF: Soil-plant spectral diagnostics laboratoryICRAF: Soil-plant spectral diagnostics laboratory
ICRAF: Soil-plant spectral diagnostics laboratory
 
Ghana
GhanaGhana
Ghana
 
Ethiopia
EthiopiaEthiopia
Ethiopia
 
Item 15
Item 15Item 15
Item 15
 
Item 14
Item 14Item 14
Item 14
 
Item 13
Item 13Item 13
Item 13
 
Item 7
Item 7Item 7
Item 7
 
Item 6
Item 6Item 6
Item 6
 
Item 3
Item 3Item 3
Item 3
 
Item 16
Item 16Item 16
Item 16
 
Item 9: Soil mapping to support sustainable agriculture
Item 9: Soil mapping to support sustainable agricultureItem 9: Soil mapping to support sustainable agriculture
Item 9: Soil mapping to support sustainable agriculture
 
Item 8: WRB, World Reference Base for Soil Resouces
Item 8: WRB, World Reference Base for Soil ResoucesItem 8: WRB, World Reference Base for Soil Resouces
Item 8: WRB, World Reference Base for Soil Resouces
 
Item 7: Progress made in Nepal
Item 7: Progress made in NepalItem 7: Progress made in Nepal
Item 7: Progress made in Nepal
 
Item 6: International Center for Biosaline Agriculture
Item 6: International Center for Biosaline AgricultureItem 6: International Center for Biosaline Agriculture
Item 6: International Center for Biosaline Agriculture
 

Kürzlich hochgeladen

psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 

Kürzlich hochgeladen (20)

psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 

Essentials of R

  • 1. Essentials of a Bas Kempen © ISRIC-World Soil Information, 2017. Reproduction or dissemination of the work as a whole or parts is not permitted without consent of the author. Sale or placement on a website where payment must be made to access the document is strictly prohibited. https://creativecommons.org/licenses/by-nc-nd/4.0/
  • 2. What is R? • R is a free software environment for statistical computing and graphics • R provides a wide variety of statistical (linear and nonlinear modelling, classical statistical tests, time-series analysis, classification, clustering, …) and graphical techniques, and is highly extensible. – Base functionality (comes with R installation) – Extension via ‘Packages’ (~6,700) • www.r-project.org/ • www.r-tutor.com
  • 3. Why R? • It is free • It runs on a variety of platforms • Platform for (advanced) statistical data analyses • State-of-the-art graphic capabilities • Connects with other software (SAGA GIS, GE, Python) • Very large user community on the web; lots of resources • R has a steep learning curve • Thousands of packages, not always easy to find what you are looking for • Sometimes cryptic error messages • Not a GIS
  • 6. First steps..... • Tell R where to find and save your files: setting the working directory using the ‘setwd’ command: – setwd(“D:/Bas/SpringSchool/Rintro/workingdir”) – setwd(“D:BasSpringSchoolRintroworkingdir”) • Load packages that are required for your analyses: – library(gstat) – require(gstat) (packages should be installed on your computer) • Note: R is case-sensitive!
  • 7. Setting up your session
  • 8. R scripts and data objects • R scripts are saved as “<name>.R” files • R objects in the environment can be saved for future use. • Save the entire environment or only a couple of objects. • Objects are saved as “<name>.rda” or “<name>.RDATA” files
  • 9. Basic Data Types • Numeric • Integer • Logical • Character • Factor Vector Function
  • 10. Vectors • Sequence of data elements of the same basic type. • Vectors can be combined.
  • 11. Vector arithmetic • Vectorized operations: most operations work on vectors with the same syntax as they work on scalars (no need for looping) • Vector arithmetic: • Recycling of vector elements:
  • 12. Other data structures • Matrices • Lists • Data frames • Data frame is the fundamental data structure for statistical modelling in R. • Data frame is a table with columns and rows (fields and records).
  • 13. Data frame • Columns can have different data types (numeric, integer, logical, character, factor) • All columns must have the same length
  • 14. Selecting subsets • Selection is done with ‘[...]’ • Vector: • Data frame:
  • 15. Functions • Data analyses and modelling is done through functions. • These can be very simple: • More complex functions have multiple arguments (inputs) • Arguments have specific requirements • Access help: ?fit.variogram
  • 16. Plotting • Large number of packages and functions for generating plots with basic functionality to ‘high-level’: e.g. lattice and ggplot. • The basic function for plotting is ‘plot’
  • 17. ggplot (http://ggplot2.org/) • library(ggplot2) • Build your plot layer by layer • Building blocks: – geom: the geometric object that describes the type of plot that is produced. – aes: ‘aesthetics’, defines the visual properties of the variables that are going to be plotted. – scales: control the legend, plot layout
  • 22. Importing data • Importing from tables: – csv: read.csv() – txt: read.table() – xlxs: read.xlsx() [requires package ‘xlsx’] • Data is imported as a data.frame
  • 23. Exporting data • Variety of exporting formats for tabular data: • Saving plots
  • 24. Working with spatial data in R
  • 25. Spatial Data in R • R offers a wide variety of packages and tools that can handle spatial data. • Note: R is not a GIS. • R is not so memory efficient. • Relevant packages: – sp: handling spatial data – raster: reading/manipulating/writing spatial raster data – rgdal: reading/writing spatial data – maptools: reading/manipulating/writing spatial polygon data (not maintained anymore)
  • 26. Spatial data classes and formats • Vector: points, lines and polygons (areal). • For storing data that has discrete boundaries, such as country borders, land parcels, and streets. • Format: shapefile
  • 27. Spatial data classes and formats • Raster: surface divided into a regular grid of cells. • For storing data that varies continuously, as in a satellite image, a surface of chemical concentrations, or an elevation surface. • Format: GeoTiff (allows embedding spatial reference information, metadata and color legends. It also supports internal compression) • (Ascii, ESRI Grid)
  • 28. Structures for spatial data • Spatial data is nothing more than a data frame that has columns with X and Y coordinates. • Example: • Let’s now take a look at R classes for spatial data (sp package)
  • 29. Spatial data classes I • Convert a data frame to a SpatialPointsDataFrame object with the coordinates function.
  • 30. Spatial data classes I • Data frame with data points at regular intervals.
  • 31. Spatial data classes II • Create a grid object with the gridded function: SpatialPixelsDataFrame
  • 32. Spatial data classes III • Create a full grid object with the fullgrid function: SpatialGridDataFrame
  • 33. Spatial data classes IV • The sp class for polygon data is the SpatialPolygonsDataFrame.
  • 34. Spatial data classes VI • The raster package comes with its own class for raster data: RasterLayer.
  • 35. Importing spatial data • rgdal: readOGR (vector), readGDAL (raster) • maptools: readShapePoly, readShapePoints, readShapeLines (functions not maintained anymore) • raster: raster
  • 36. Projections • Once you have loaded your spatial data in R, you have to tell R its geographic projection. • Check the current projection: proj4string function. • Setting a projection: CRS function. • Reprojecting to another coordinate system: spTransform function.
  • 44. Interactive maps • Interactive maps can be generated with the leaflet package.
  • 45. Exporting spatial data • rgdal: writeOGR (vector), writeGDAL (raster) • maptools: writePolyShape, writePointsShape • raster: writeRaster
  • 46. Now lets practice. Have fun!!