SlideShare ist ein Scribd-Unternehmen logo
1 von 88
Downloaden Sie, um offline zu lesen
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
R crash course
(for people who pick up new methods/tools quickly
and have a high motivation to learn)
T. Hengl1 & R.S. Bivand2
1Instituut voor Biodiversiteit en Ecosysteem Dynamica
Universiteit van Amsterdam
2Department of Economics
Norwegian School of Economics and Business administration
June 19, 2010
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Outline
1 Overview
Course programme
Why R?
Software installation
2 Scripting in R
Do’s and don’ts
R code editors
3 Working with spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google Earth
4 Literature
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Programme
Installation and first (baby) steps (intro.R).
Building, running and editing models in R.
Working with spatial data.
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Crash course
A“crash course”is a compressed version of a training course for
people that already have full agendas. It is really intended for
people who pick up new methods/tools quickly and have a high
motivation to learn (PhD students?). This means no long
questions, no going back, no long discussion, no complains
about the speed/programme of the course. . . and of course: no
promises that you will manage to learn R in such a short time.
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
The course programme
Basic concepts (self-study)
R basic and add-on packages;
R syntax; R objects and ’methods’;
R FAQs; getting help and the most important literature;
Scripting in R
data management; creating and debugging scripts
(scripting editors: Tinn-R);
automating analysis — making functions and packages;
publication quality outputs (using R+Sweave);
Advanced topics
GDAL and R; spatial classes and packages;
calling external applications from R (SAGA GIS, FWTools,
Python, Matlab;
export of maps to Google Earth;
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Outline
1 Overview
Course programme
Why R?
Software installation
2 Scripting in R
Do’s and don’ts
R code editors
3 Working with spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google Earth
4 Literature
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Getting the right motivation (inspiration)
What is R, and why should you invest time to learn it?
What can it do? (and what it can’t do?)
How does the R community works (what are its shared
principles)?
Is R suited for spatio-temporal data analysis?
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Some important assumptions
R is (increasingly) sexy.
R is hell.
You are all beginners (who need a gentle intro).
You are non-statisticians / computer scientists.
I learned R myself. If I can do it, you can do it too.
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Some important assumptions
R is (increasingly) sexy.
R is hell.
You are all beginners (who need a gentle intro).
You are non-statisticians / computer scientists.
I learned R myself. If I can do it, you can do it too.
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Some important assumptions
R is (increasingly) sexy.
R is hell.
You are all beginners (who need a gentle intro).
You are non-statisticians / computer scientists.
I learned R myself. If I can do it, you can do it too.
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Some important assumptions
R is (increasingly) sexy.
R is hell.
You are all beginners (who need a gentle intro).
You are non-statisticians / computer scientists.
I learned R myself. If I can do it, you can do it too.
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Some important assumptions
R is (increasingly) sexy.
R is hell.
You are all beginners (who need a gentle intro).
You are non-statisticians / computer scientists.
I learned R myself. If I can do it, you can do it too.
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
What is R?
the open source implementation of the S language for
statistical computing created by created by Ross Ihaka
and Robert Gentleman (now maintained by the R
Development Core Team);
why R?: the name“R”was selected for two reasons: (1)
precedence —“R”is a letter before“S”, and (2) coincidence
— both of the creators’ names start with a letter“R”;
it is a computer language developed to simplify statistical
computing/programming;
it offers many contributed packages, technical documents,
demos and examples;
widely recognized as one of the fastest growing and most
comprehensive statistical computing tools;
it is a movement;
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
What is R?
the open source implementation of the S language for
statistical computing created by created by Ross Ihaka
and Robert Gentleman (now maintained by the R
Development Core Team);
why R?: the name“R”was selected for two reasons: (1)
precedence —“R”is a letter before“S”, and (2) coincidence
— both of the creators’ names start with a letter“R”;
it is a computer language developed to simplify statistical
computing/programming;
it offers many contributed packages, technical documents,
demos and examples;
widely recognized as one of the fastest growing and most
comprehensive statistical computing tools;
it is a movement;
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
What is R?
the open source implementation of the S language for
statistical computing created by created by Ross Ihaka
and Robert Gentleman (now maintained by the R
Development Core Team);
why R?: the name“R”was selected for two reasons: (1)
precedence —“R”is a letter before“S”, and (2) coincidence
— both of the creators’ names start with a letter“R”;
it is a computer language developed to simplify statistical
computing/programming;
it offers many contributed packages, technical documents,
demos and examples;
widely recognized as one of the fastest growing and most
comprehensive statistical computing tools;
it is a movement;
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
What is R?
the open source implementation of the S language for
statistical computing created by created by Ross Ihaka
and Robert Gentleman (now maintained by the R
Development Core Team);
why R?: the name“R”was selected for two reasons: (1)
precedence —“R”is a letter before“S”, and (2) coincidence
— both of the creators’ names start with a letter“R”;
it is a computer language developed to simplify statistical
computing/programming;
it offers many contributed packages, technical documents,
demos and examples;
widely recognized as one of the fastest growing and most
comprehensive statistical computing tools;
it is a movement;
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
What is R?
the open source implementation of the S language for
statistical computing created by created by Ross Ihaka
and Robert Gentleman (now maintained by the R
Development Core Team);
why R?: the name“R”was selected for two reasons: (1)
precedence —“R”is a letter before“S”, and (2) coincidence
— both of the creators’ names start with a letter“R”;
it is a computer language developed to simplify statistical
computing/programming;
it offers many contributed packages, technical documents,
demos and examples;
widely recognized as one of the fastest growing and most
comprehensive statistical computing tools;
it is a movement;
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
What is R?
the open source implementation of the S language for
statistical computing created by created by Ross Ihaka
and Robert Gentleman (now maintained by the R
Development Core Team);
why R?: the name“R”was selected for two reasons: (1)
precedence —“R”is a letter before“S”, and (2) coincidence
— both of the creators’ names start with a letter“R”;
it is a computer language developed to simplify statistical
computing/programming;
it offers many contributed packages, technical documents,
demos and examples;
widely recognized as one of the fastest growing and most
comprehensive statistical computing tools;
it is a movement;
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
R is“sexy”
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Quote
“R has really become the second language for people
coming out of grad school now, and there’s an
amazing amount of code being written for it.”
Max Kuhn
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
What it is NOT
it’s not a software with GUI and point-and-click control;
there are practically no data analysis wizards;
it’s not an interactive system;
it comes with no warranties (but so does the commercial
software too!!);
there is practically no formal support;
however. . .
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
What it is NOT
it’s not a software with GUI and point-and-click control;
there are practically no data analysis wizards;
it’s not an interactive system;
it comes with no warranties (but so does the commercial
software too!!);
there is practically no formal support;
however. . .
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
What it is NOT
it’s not a software with GUI and point-and-click control;
there are practically no data analysis wizards;
it’s not an interactive system;
it comes with no warranties (but so does the commercial
software too!!);
there is practically no formal support;
however. . .
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
What it is NOT
it’s not a software with GUI and point-and-click control;
there are practically no data analysis wizards;
it’s not an interactive system;
it comes with no warranties (but so does the commercial
software too!!);
there is practically no formal support;
however. . .
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
What it is NOT
it’s not a software with GUI and point-and-click control;
there are practically no data analysis wizards;
it’s not an interactive system;
it comes with no warranties (but so does the commercial
software too!!);
there is practically no formal support;
however. . .
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
What it is NOT
it’s not a software with GUI and point-and-click control;
there are practically no data analysis wizards;
it’s not an interactive system;
it comes with no warranties (but so does the commercial
software too!!);
there is practically no formal support;
however. . .
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Why make scripts?
It’s easy to use: “Because S (and its implementation R) is
a well-developed, simple and effective programming
language which includes conditionals, loops, user-defined
recursive functions and input and output facilities, existing
functions can be modified.” In R we all become
programmers (but much faster than with C++ or Java).
The basic approach to using R is to generate scripts that
define the data processing steps (workflows?).
Documenting the analysis process is a“good thing”, so
programming scripts are not just a burden, certainly for
users doing original research and repetitive work, arguably
for student classes too.
Point-and-click operations are for amateurs.
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Why make scripts?
It’s easy to use: “Because S (and its implementation R) is
a well-developed, simple and effective programming
language which includes conditionals, loops, user-defined
recursive functions and input and output facilities, existing
functions can be modified.” In R we all become
programmers (but much faster than with C++ or Java).
The basic approach to using R is to generate scripts that
define the data processing steps (workflows?).
Documenting the analysis process is a“good thing”, so
programming scripts are not just a burden, certainly for
users doing original research and repetitive work, arguably
for student classes too.
Point-and-click operations are for amateurs.
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Why make scripts?
It’s easy to use: “Because S (and its implementation R) is
a well-developed, simple and effective programming
language which includes conditionals, loops, user-defined
recursive functions and input and output facilities, existing
functions can be modified.” In R we all become
programmers (but much faster than with C++ or Java).
The basic approach to using R is to generate scripts that
define the data processing steps (workflows?).
Documenting the analysis process is a“good thing”, so
programming scripts are not just a burden, certainly for
users doing original research and repetitive work, arguably
for student classes too.
Point-and-click operations are for amateurs.
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Why make scripts?
It’s easy to use: “Because S (and its implementation R) is
a well-developed, simple and effective programming
language which includes conditionals, loops, user-defined
recursive functions and input and output facilities, existing
functions can be modified.” In R we all become
programmers (but much faster than with C++ or Java).
The basic approach to using R is to generate scripts that
define the data processing steps (workflows?).
Documenting the analysis process is a“good thing”, so
programming scripts are not just a burden, certainly for
users doing original research and repetitive work, arguably
for student classes too.
Point-and-click operations are for amateurs.
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Do you speak R?
After some time you basically discovered that most of the things
you want to do, you can do in R, the only question is how.
Well, first, you have to learn to how to speak’n’write R.
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Why NOT Matlab?
R and Matlab are in fact very similar, except. . . :
(almost) everything you do in Matlab, you can do in R;
R can be used to write homework (for Matlab you need a
computer lab with software licences);
“R gradually pushes people towards better programming
habits”(Tam´as K. Papp);
Matlab has a limited support for processing spatial data (R
is better);
Contributed packages in R are growing faster (R is better);
We are in academia — we shouldn’t be developing
toolboxes for some private company but for the people
(and for ourselves);
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
A bit of history
R was first time released in 1997;
majority of the development is (still) done by prof. Brian
D. Ripley;
a the moment (juni 19 2010 10:01), there are 2387
contributed packages!
according to Google trends, R-project.org has a
community of about 200–350k active users;
in 2003, a group of researchers (International Workshop on
Distributed Statistical Computing) decided to add Spatial
functionality to R;
. . . now is time to use it more broadly (MSc level and PhD
level modules, projects, reports and scientific documents);
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Quote
“Once methodological problems start being perceived
or even defined in terms of what one’s favorite
software does well, then the software has stopped
being a tool, and has become a crutch, and at worse a
shackle.”
Simon Jackman
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
The ASDA(R)-book.org
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
The ASDA(R) team
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
A Practical Guide to Geostatistical Mapping
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Quote
“I created Quick-R for one simple reason. I wanted to
learn R and I am a teacher at heart. The easiest way
for me to learn something is to teach it”
Robert I. Kabacoff
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Outline
1 Overview
Course programme
Why R?
Software installation
2 Scripting in R
Do’s and don’ts
R code editors
3 Working with spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google Earth
4 Literature
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Software
Not all software is required to follow the exercises
R v2.11 (Windows OS) including a list of packages;
Tinn-R v2.3 (code editor);
Optional: FWTools v2.4 — a list of utilities to handle
spatial data; SAGA GIS v2.0.4 — a light GIS excellent for
educational purposes.
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Installing the add-on packages
> install.packages("ctv")
> library(ctv)
> install.views("Spatial")
This will install all connected packages listed at R views Spatial.
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Check your installation
> Sys.getenv(c("OS", "COMPUTERNAME", "R_HOME", "R_LIBS_USER",
+ "PROCESSOR_IDENTIFIER"))
OS
"Windows_NT"
COMPUTERNAME
"PC-IBED193"
R_HOME
"C:PROGRA~1RR-210~1.1"
R_LIBS_USER
"n:/R/win-library/2.10"
PROCESSOR_IDENTIFIER
"x86 Family 6 Model 15 Stepping 6, GenuineIntel"
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Outline
1 Overview
Course programme
Why R?
Software installation
2 Scripting in R
Do’s and don’ts
R code editors
3 Working with spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google Earth
4 Literature
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Making friends with R
1 Use script editors such as as TINN-R or JGR (syntax
highlighting, wrapping, search/replace etc.).
2 The best way to learn R is to look at the existing scripts,
then extend:
Graphical Manual/Addicted to R — if you prefer to explore
examples graphically;
Teach-your-self books e.g.“Statistics with R”or“An
Introduction to R”;“Introduction to R for ITC students”
Quick-R and/or R by example;
3 If your R script does not work, do not break your head, try
to get help:
local installation: > help.search("kriging");
R-project: > RSiteSearch("krige dimensions do not
match")
www: Rseek.org
R mailing lists;
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Making friends with R
1 Use script editors such as as TINN-R or JGR (syntax
highlighting, wrapping, search/replace etc.).
2 The best way to learn R is to look at the existing scripts,
then extend:
Graphical Manual/Addicted to R — if you prefer to explore
examples graphically;
Teach-your-self books e.g.“Statistics with R”or“An
Introduction to R”;“Introduction to R for ITC students”
Quick-R and/or R by example;
3 If your R script does not work, do not break your head, try
to get help:
local installation: > help.search("kriging");
R-project: > RSiteSearch("krige dimensions do not
match")
www: Rseek.org
R mailing lists;
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Making friends with R
1 Use script editors such as as TINN-R or JGR (syntax
highlighting, wrapping, search/replace etc.).
2 The best way to learn R is to look at the existing scripts,
then extend:
Graphical Manual/Addicted to R — if you prefer to explore
examples graphically;
Teach-your-self books e.g.“Statistics with R”or“An
Introduction to R”;“Introduction to R for ITC students”
Quick-R and/or R by example;
3 If your R script does not work, do not break your head, try
to get help:
local installation: > help.search("kriging");
R-project: > RSiteSearch("krige dimensions do not
match")
www: Rseek.org
R mailing lists;
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Making friends with R
1 Use script editors such as as TINN-R or JGR (syntax
highlighting, wrapping, search/replace etc.).
2 The best way to learn R is to look at the existing scripts,
then extend:
Graphical Manual/Addicted to R — if you prefer to explore
examples graphically;
Teach-your-self books e.g.“Statistics with R”or“An
Introduction to R”;“Introduction to R for ITC students”
Quick-R and/or R by example;
3 If your R script does not work, do not break your head, try
to get help:
local installation: > help.search("kriging");
R-project: > RSiteSearch("krige dimensions do not
match")
www: Rseek.org
R mailing lists;
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Making friends with R
1 Use script editors such as as TINN-R or JGR (syntax
highlighting, wrapping, search/replace etc.).
2 The best way to learn R is to look at the existing scripts,
then extend:
Graphical Manual/Addicted to R — if you prefer to explore
examples graphically;
Teach-your-self books e.g.“Statistics with R”or“An
Introduction to R”;“Introduction to R for ITC students”
Quick-R and/or R by example;
3 If your R script does not work, do not break your head, try
to get help:
local installation: > help.search("kriging");
R-project: > RSiteSearch("krige dimensions do not
match")
www: Rseek.org
R mailing lists;
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Making friends with R
1 Use script editors such as as TINN-R or JGR (syntax
highlighting, wrapping, search/replace etc.).
2 The best way to learn R is to look at the existing scripts,
then extend:
Graphical Manual/Addicted to R — if you prefer to explore
examples graphically;
Teach-your-self books e.g.“Statistics with R”or“An
Introduction to R”;“Introduction to R for ITC students”
Quick-R and/or R by example;
3 If your R script does not work, do not break your head, try
to get help:
local installation: > help.search("kriging");
R-project: > RSiteSearch("krige dimensions do not
match")
www: Rseek.org
R mailing lists;
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Making friends with R
1 Use script editors such as as TINN-R or JGR (syntax
highlighting, wrapping, search/replace etc.).
2 The best way to learn R is to look at the existing scripts,
then extend:
Graphical Manual/Addicted to R — if you prefer to explore
examples graphically;
Teach-your-self books e.g.“Statistics with R”or“An
Introduction to R”;“Introduction to R for ITC students”
Quick-R and/or R by example;
3 If your R script does not work, do not break your head, try
to get help:
local installation: > help.search("kriging");
R-project: > RSiteSearch("krige dimensions do not
match")
www: Rseek.org
R mailing lists;
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Making friends with R
1 Use script editors such as as TINN-R or JGR (syntax
highlighting, wrapping, search/replace etc.).
2 The best way to learn R is to look at the existing scripts,
then extend:
Graphical Manual/Addicted to R — if you prefer to explore
examples graphically;
Teach-your-self books e.g.“Statistics with R”or“An
Introduction to R”;“Introduction to R for ITC students”
Quick-R and/or R by example;
3 If your R script does not work, do not break your head, try
to get help:
local installation: > help.search("kriging");
R-project: > RSiteSearch("krige dimensions do not
match")
www: Rseek.org
R mailing lists;
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Making friends with R
1 Use script editors such as as TINN-R or JGR (syntax
highlighting, wrapping, search/replace etc.).
2 The best way to learn R is to look at the existing scripts,
then extend:
Graphical Manual/Addicted to R — if you prefer to explore
examples graphically;
Teach-your-self books e.g.“Statistics with R”or“An
Introduction to R”;“Introduction to R for ITC students”
Quick-R and/or R by example;
3 If your R script does not work, do not break your head, try
to get help:
local installation: > help.search("kriging");
R-project: > RSiteSearch("krige dimensions do not
match")
www: Rseek.org
R mailing lists;
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Making friends with R
1 Use script editors such as as TINN-R or JGR (syntax
highlighting, wrapping, search/replace etc.).
2 The best way to learn R is to look at the existing scripts,
then extend:
Graphical Manual/Addicted to R — if you prefer to explore
examples graphically;
Teach-your-self books e.g.“Statistics with R”or“An
Introduction to R”;“Introduction to R for ITC students”
Quick-R and/or R by example;
3 If your R script does not work, do not break your head, try
to get help:
local installation: > help.search("kriging");
R-project: > RSiteSearch("krige dimensions do not
match")
www: Rseek.org
R mailing lists;
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Good practice
Put comments in script (after #).
Add some meta-information at the beginning of your
script.
Once you tested your script and saw that it works, tidy-up
the code.
Place the input data on-line (database) so you can
communicate only the script.
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
R mailing lists: Do’s and Don’ts!
Do’s:
If you have not done so already, read the R posting guide.
Use the existing pre-installed data sets (come together with
a certain package) to describe your problem; link your
problem to some existing problems.
Acknowledge the work (time spent) other people do to help
you.
You can submit not only the problems you discover but also
the information that you think is interesting for the
community.
Don’ts:
Do not send poorly formulated questions.
Do not send too much.
Complaining to a mailing list about what frustrates you
about R makes no sense.
You are requesting that somebody does a work for you that
you could do yourself!
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Outline
1 Overview
Course programme
Why R?
Software installation
2 Scripting in R
Do’s and don’ts
R code editors
3 Working with spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google Earth
4 Literature
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Tinn-R
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
JaGuaR
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Outline
1 Overview
Course programme
Why R?
Software installation
2 Scripting in R
Do’s and don’ts
R code editors
3 Working with spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google Earth
4 Literature
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Spatial objects
An advantage of R (as compared to e.g. Matlab) is that you
can create your own formats and structures for data. But if
there are too many formats you can easily get lots. In addition,
we want to have smooth links to external formats (R is open!).
To reduce this problem, Bivand et al. (2008) developed
new-style classes to represent spatial data.
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Spatial class
The foundation object is the Spatial class, with just two basic
slots (new-style S classes have pre-defined components called
slots):
a bounding box — mostly used for setting up plots;
a CRS class object — defining the coordinate reference
system, and may be set to CRS(as.character(NA));
Operations on Spatial* objects should update or copy these
values to the new Spatial* objects being created. The most
basic spatial data object is a point, which may have 2 or 3
dimensions.
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Spatial classes
for point features: SpatialPoints;
SpatialPointsDataFrame;
for line features: SpatialLines,
SpatialLinesDataFrame;
polygons: SpatialPolygons,
SpatialPolygonsDataFrame;
rasters: SpatialPixels, SpatialPixelsDataFrame,
SpatialGrid, SpatialGridDataFrame;
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
SpatialPoints
> library(sp)
> data(meuse)
> coords <- SpatialPoints(meuse[, c("x", "y")])
> summary(coords)
Object of class SpatialPoints
Coordinates:
min max
x 178605 181390
y 329714 333611
Is projected: NA
proj4string : [NA]
Number of points: 155
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
SpatialPointsDataFrame
We can add the tabular data to make a
SpatialPointsDataFrame object:
> meuse1 <- SpatialPointsDataFrame(coords, meuse)
> str(meuse1, max.level = 2)
Formal class 'SpatialPointsDataFrame' [package "sp"] with 5 slots
..@ data :'data.frame': 155 obs. of 14 variables:
..@ coords.nrs : num(0)
..@ coords : num [1:155, 1:2] 181072 181025 181165 ...
.. ..- attr(*, "dimnames")=List of 2
..@ bbox : num [1:2, 1:2] 178605 329714 181390 333611
.. ..- attr(*, "dimnames")=List of 2
..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slots
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Point features
ments
Spatial points classes and their slots
coords
Spatial
coords.nrs
data
SpatialPoints bbox
proj4string
SpatialPointsDataFrame
data.frame
Spatial
SpatialPoints
Spatial lines and polygons
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Line/polygon features
dge
m a
ns
Spatial Polygons classes and slots
coords
Spatial
lines
plotOrder
Spatial
polygons
bbox
proj4string
Polygon
coords
labpt
area
hole
ringDir
LineLines
ID
Polygons
plotOrder
labpt
ID
area
SpatialLines
Spatial
SpatialPolygons
Lines
Polygons
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Grids
e bank
he data
m the
Spatial grid and pixels classes and their slots
data
SpatialPixels
SpatialGrid
data grid
grid.index
SpatialPoints
grid
grid.index
SpatialPoints
cellcentre.offset
cellsize
cells.dim
coords
Spatial
bbox
proj4string
data.frame
Spatial
GridTopology
SpatialPoints
SpatialGridDataFrame
SpatialGrid
SpatialPixels
SpatialPixelsDataFrame
Spatial classes provided by sp
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Outline
1 Overview
Course programme
Why R?
Software installation
2 Scripting in R
Do’s and don’ts
R code editors
3 Working with spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google Earth
4 Literature
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Basic methods
spplot — plotting of spatial objects (maps);
spsample — sample points from a set of polygons, on a
set of lines or from a gridded area;
bbox — get the bounding box;
proj4string — get or set the projection (coordinate
reference system);
coordinates — set or retrieve coordinates;
spTransform — transform coordinates from one CRS to
another;
overlay — combine two different spatial objects;
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Plotting a SpatialPoints object
> plot(as(meuse1, "Spatial"), axes = TRUE)
> plot(meuse1, add = TRUE)
> plot(meuse1[meuse1$ffreq == 1, ], col = "green", add = TRUE)
178000 179000 180000 181000 182000
330000331000332000333000
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Combining statistical and GIS operations
Because the Spatial*DataFrame family objects behave in
most cases like data frames, most of what we are used to
doing with standard data frames just works (but no merge,
etc., yet).
These objects are very similar to typical representations of
the same kinds of objects in geographical information
systems, so they do not suit spatial data that is not
geographical (like medical imaging) as such.
Because now sp classes for GIS data exits, this opens the
door for fusing GIS and statistical operations (this has not
been possible in e.g. 2002).
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Spatial packages
R now offers a range of contributed packages in spatial
statistics and increasing awareness of the importance of spatial
data analysis in the broader community. Current contributed
packages with spatial applications:
point patterns: spatstat, VR:spatial, splancs;
geostatistics: gstat, geoR, geoRglm, fields, spBayes,
RandomFields, VR:spatial, sgeostat, vardiag;
lattice/area data: spdep, DCluster, spgwr, ade4;
links to GIS: rgdal, spgrass, RPy, RSAGA;
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Let’s create spatial objects!
We can create spatial objects from scratch! For example a
DEM:
> dem <- expand.grid(x = seq(100, 600, 100), y = seq(100,
+ 600, 100))
> dem$Z <- as.vector(c(23, 24, 34, 38, 45, 51, 24, 20,
+ 20, 28, 18, 49, 22, 20, 19, 14, 38, 45, 19, 15, 13,
+ 21, 23, 25, 14, 11, 18, 11, 18, 19, 10, 16, 23, 16,
+ 9, 6))
> gridded(dem) <- ~x + y
> dem <- as(dem, "SpatialGridDataFrame")
> str(dem)
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
A small DEM
> dem.plt <- spplot(dem[1], main = "DEM", scales = list(draw = FALSE),
+ col.regions = topo.colors(25))
> print(dem.plt)
> writeGDAL(dem, "dem6.sdat", "SAGA")
DEM
10
20
30
40
50
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Outline
1 Overview
Course programme
Why R?
Software installation
2 Scripting in R
Do’s and don’ts
R code editors
3 Working with spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google Earth
4 Literature
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Controlling SAGA from R
> library(RSAGA)
> rsaga.env()
$workspace
[1] "."
$cmd
[1] "saga_cmd.exe"
$path
[1] "C:/PROGRA~1/R/R-210~1.1/library/RSAGA/saga_vc"
$modules
[1] "C:/PROGRA~1/R/R-210~1.1/library/RSAGA/saga_vc/modules"
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Getting list of modules
> rsaga.get.modules("ta_channels")
$ta_channels
code name interactive
1 0 Channel Network FALSE
2 1 Watershed Basins FALSE
3 2 Watershed Basins (extended) FALSE
4 3 Vertical Distance to Channel Network FALSE
5 4 Overland Flow Distance to Channel Network FALSE
6 5 D8 Flow Analysis FALSE
7 6 Strahler Order FALSE
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Run stream extraction
> rsaga.geoprocessor(lib = "ta_channels", module = 5, param = list(DEM = "
+ DIRECTION = "channels.sgrd", CONNECTION = "route.sgrd",
+ NETWORK = "channels.shp"))
SAGA CMD 2.0.4
library path: C:/PROGRA~1/R/R-210~1.1/library/RSAGA/...
library name: ta_channels
module name : D8 Flow Analysis
author : (c) 2003 by O.Conrad
Load grid: dem6.sgrd...
ready
Parameters
Grid system: 100; 6x 6y; 100x 100y
DEM: dem6
Flow Direction: Flow Direction
Flow Connectivity: Flow Connectivity
Flow Network: Flow Network
Minimum Connectivity: 0
...
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Read back to R
> dem$route <- readGDAL("route.sdat")$band1
route.sdat has GDAL driver SAGA
and has 6 rows and 6 columns
> channels <- readOGR("channels.shp", "channels")
OGR data source with driver: ESRI Shapefile
Source: "channels.shp", layer: "channels"
with 32 features and 2 fields
Feature type: wkbLineString with 2 dimensions
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Plot the final result
> dem.plt <- spplot(dem[1], main = "DEM", col.regions = topo.colors(25))
> channels.plt <- spplot(dem[2], col.regions = rev(gray(0:20/20)),
+ main = "Flow connectivity", sp.layout = list("sp.lines",
+ channels, col = "red"))
> print(dem.plt, split = c(1, 1, 2, 1), more = T)
> print(channels.plt, split = c(2, 1, 2, 1), more = F)
DEM
10
20
30
40
50
Flow connectivity
0.0
0.5
1.0
1.5
2.0
2.5
3.0
3.5
4.0
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Outline
1 Overview
Course programme
Why R?
Software installation
2 Scripting in R
Do’s and don’ts
R code editors
3 Working with spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google Earth
4 Literature
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Preparing FWTools
There is still no package to control FWTools from R, but we can
simply send command lines using the system command. Before
we can use FWTools from R, we need to locate it on our PC:
> gdalwarp <- gsub("/", "", dir(path="C:/PROGRA~2/FWTOOL~1.7",
+ pattern="gdalwarp.exe", recursive=TRUE, full.names=TRUE))
> gdalwarp
[1] "C:PROGRA~2FWTOOL~1.7bingdalwarp.exe"
> workd <- paste(gsub("/", "", getwd()), "", sep="")
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
MODIS data
Now we can download some GIS data from web:
> MOD12Q1 <- "ftp://anonymous:test@e4ftl01u.ecs.nasa.gov/
+ MOLT/MOD12Q1.004/2004.01.01/"
> download.file(paste(MOD12Q1,
+ "MOD12Q1.A2004001.h18v03.004.2006117173748.hdf", sep=""),
+ destfile=paste(getwd(),
+ "MOD12Q1.A2004001.h18v03.004.2006117173748.hdf", sep="/"),
+ mode='wb', method='wget')
Resolving e4ftl01u.ecs.nasa.gov... 152.61.4.83
Connecting to e4ftl01u.ecs.nasa.gov|152.61.4.83|:21... connected.
Logging in as anonymous ... Logged in!
==> SYST ... done. ==> PWD ... done.
==> TYPE I ... done. ==> CWD /MOLT/MOD12Q1.004/2004.01.01 ... done.
==> SIZE MOD12Q1.A2004001.h18v03.004.2006117173748.hdf ... 23165983
==> PASV ... done. ==> RETR MOD12Q1.A2004... done.
Length: 23165983 (22M)
0K .......... .......... 0% 64.9K 5m48s
...
22550K .......... .......... 99% 501K 0s
22600K .......... 100% 503K=65s
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Reprojecting grids
We can reproject/resample the map to our local coordinate
system using the gdalwarp functionality (this combines several
processing steps in one function):
> NL.prj <- "+proj=sterea +lat_0=52.15616055555555
+ +lon_0=5.38763888888889 +k=0.999908 +x_0=155000
+ +y_0=463000 +ellps=bessel +units=m +no_defs
+ +towgs84=565.237,50.0087,465.658,
+ -0.406857,0.350733,-1.87035,4.0812"
> system(paste(gdalwarp, " HDF4_EOS:EOS_GRID:"", workd,
+ "MOD12Q1.A2004001.h18v03.004.2006117173748.hdf"
+ :MOD12Q1:Land_Cover_Type_1 -t_srs "", NL.prj, ""
+ IGBP2004NL.tif -r near -te 0 300000 280000 625000
+ -tr 500 500", sep=""))
Creating output file that is 560P x 650L.
Processing input file HDF4_EOS:EOS_GRID:MOD12Q1.A2004001...
Using internal nodata values (eg. 255) for image HDF4_EOS:EOS_...
0...10...20...30...40...50...60...70...80...90...100 - done.
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Plot the final result
In this case we have produced a MODIS-based land cover map
for the whole Netherlands in resolution of 500 m (in local
coordinate system).
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Outline
1 Overview
Course programme
Why R?
Software installation
2 Scripting in R
Do’s and don’ts
R code editors
3 Working with spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google Earth
4 Literature
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Writing spatial data to KML
There are two possibilities to export maps to KML: (a)
using existing packages, and (b) by writing KML files
“by-hand”.
To export point or line features to KML, use the writeOGR
method that is available in R package rgdal.
More flexible way to writing KML files is by using loops.
R crash
course
T. Hengl &
R.S. Bivand
Overview
Course programme
Why R?
Software installation
Scripting in R
Do’s and don’ts
R code editors
Working with
spatial data
Spatial classes
Spatial methods
R+SAGA
R+FWTools
Export to Google
Earth
Literature
Literature
Bivand, R., Pebesma, E., Rubio, V., 2008. Applied Spatial
Data Analysis with R. Use R Series, Springer, Heidelberg,
378 p.
Hengl, T., 2009. A Practical Guide to Geostatistical
Mapping, 2nd edition. University of Amsterdam, 291 p.
ISBN 978-90-9024981-0.
Kabacoff, R.I., 2009. Data Analysis and Graphics with R.
Manning publications, 375 p.
Zuur, A. F., Ieno, E. N., Meesters, E. H. W. G., 2009. A
Beginner’s Guide to R. Springer, Use R series, 228 p.

Weitere ähnliche Inhalte

Was ist angesagt?

A short tutorial on r
A short tutorial on rA short tutorial on r
A short tutorial on rAshraf Uddin
 
NumPy and SciPy for Data Mining and Data Analysis Including iPython, SciKits,...
NumPy and SciPy for Data Mining and Data Analysis Including iPython, SciKits,...NumPy and SciPy for Data Mining and Data Analysis Including iPython, SciKits,...
NumPy and SciPy for Data Mining and Data Analysis Including iPython, SciKits,...Ryan Rosario
 
Cheminformatics in R
Cheminformatics in RCheminformatics in R
Cheminformatics in RRajarshi Guha
 
Chemical Data Mining: Open Source & Reproducible
Chemical Data Mining: Open Source & ReproducibleChemical Data Mining: Open Source & Reproducible
Chemical Data Mining: Open Source & ReproducibleRajarshi Guha
 
Python utilities for data presentation
Python utilities for data presentationPython utilities for data presentation
Python utilities for data presentationCommand Prompt., Inc
 
WiNGS 2014 Workshop 2 R, RStudio, and reproducible research with knitr
WiNGS 2014 Workshop 2 R, RStudio, and reproducible research with knitrWiNGS 2014 Workshop 2 R, RStudio, and reproducible research with knitr
WiNGS 2014 Workshop 2 R, RStudio, and reproducible research with knitrAnn Loraine
 
Which Programming Language is the best one?
Which Programming Language is the best one?Which Programming Language is the best one?
Which Programming Language is the best one?Ricardo Terra
 
Knowing your Garbage Collector / Python Madrid
Knowing your Garbage Collector / Python MadridKnowing your Garbage Collector / Python Madrid
Knowing your Garbage Collector / Python Madridfcofdezc
 

Was ist angesagt? (13)

A short tutorial on r
A short tutorial on rA short tutorial on r
A short tutorial on r
 
Resume
ResumeResume
Resume
 
Rcpp
RcppRcpp
Rcpp
 
R Intro
R IntroR Intro
R Intro
 
NumPy and SciPy for Data Mining and Data Analysis Including iPython, SciKits,...
NumPy and SciPy for Data Mining and Data Analysis Including iPython, SciKits,...NumPy and SciPy for Data Mining and Data Analysis Including iPython, SciKits,...
NumPy and SciPy for Data Mining and Data Analysis Including iPython, SciKits,...
 
Cheminformatics in R
Cheminformatics in RCheminformatics in R
Cheminformatics in R
 
Chemical Data Mining: Open Source & Reproducible
Chemical Data Mining: Open Source & ReproducibleChemical Data Mining: Open Source & Reproducible
Chemical Data Mining: Open Source & Reproducible
 
Introduction
IntroductionIntroduction
Introduction
 
2
22
2
 
Python utilities for data presentation
Python utilities for data presentationPython utilities for data presentation
Python utilities for data presentation
 
WiNGS 2014 Workshop 2 R, RStudio, and reproducible research with knitr
WiNGS 2014 Workshop 2 R, RStudio, and reproducible research with knitrWiNGS 2014 Workshop 2 R, RStudio, and reproducible research with knitr
WiNGS 2014 Workshop 2 R, RStudio, and reproducible research with knitr
 
Which Programming Language is the best one?
Which Programming Language is the best one?Which Programming Language is the best one?
Which Programming Language is the best one?
 
Knowing your Garbage Collector / Python Madrid
Knowing your Garbage Collector / Python MadridKnowing your Garbage Collector / Python Madrid
Knowing your Garbage Collector / Python Madrid
 

Andere mochten auch

R - Software Estatistico
R - Software EstatisticoR - Software Estatistico
R - Software EstatisticoIvan Ricarte
 
My first Beamer slide using Emacs org mode
My first Beamer slide using Emacs org mode My first Beamer slide using Emacs org mode
My first Beamer slide using Emacs org mode Dasapta Erwin Irawan
 
Introducing The R Software
Introducing The R Software  Introducing The R Software
Introducing The R Software Kamarul Imran
 
Advantages of pl sql
Advantages of pl sqlAdvantages of pl sql
Advantages of pl sqlIntellipaat
 
Introduction to R for Data Science :: Session 8 [Intro to Text Mining in R, M...
Introduction to R for Data Science :: Session 8 [Intro to Text Mining in R, M...Introduction to R for Data Science :: Session 8 [Intro to Text Mining in R, M...
Introduction to R for Data Science :: Session 8 [Intro to Text Mining in R, M...Goran S. Milovanovic
 
Data Hacking with RHadoop
Data Hacking with RHadoopData Hacking with RHadoop
Data Hacking with RHadoopEd Kohlwey
 
OBIEE Answers Vs Data Visualization: A Cage Match
OBIEE Answers Vs Data Visualization: A Cage MatchOBIEE Answers Vs Data Visualization: A Cage Match
OBIEE Answers Vs Data Visualization: A Cage MatchMichelle Kolbe
 
Diffrence between dbms and rdbms
Diffrence between dbms and rdbmsDiffrence between dbms and rdbms
Diffrence between dbms and rdbmsJitendra Thakur
 
functional dependencies with example
functional dependencies with examplefunctional dependencies with example
functional dependencies with exampleSiddhi Viradiya
 
Accessing Databases from R
Accessing Databases from RAccessing Databases from R
Accessing Databases from RJeffrey Breen
 
Hp distributed R User Guide
Hp distributed R User GuideHp distributed R User Guide
Hp distributed R User GuideAndrey Karpov
 
pl/sql online Training|sql online Training | iTeknowledge
pl/sql online Training|sql online Training | iTeknowledgepl/sql online Training|sql online Training | iTeknowledge
pl/sql online Training|sql online Training | iTeknowledgeMasood Khan
 
R + Hadoop = Big Data Analytics. How Revolution Analytics' RHadoop Project Al...
R + Hadoop = Big Data Analytics. How Revolution Analytics' RHadoop Project Al...R + Hadoop = Big Data Analytics. How Revolution Analytics' RHadoop Project Al...
R + Hadoop = Big Data Analytics. How Revolution Analytics' RHadoop Project Al...Revolution Analytics
 
Tapping the Data Deluge with R
Tapping the Data Deluge with RTapping the Data Deluge with R
Tapping the Data Deluge with RJeffrey Breen
 
Data profiling-best-practices
Data profiling-best-practicesData profiling-best-practices
Data profiling-best-practicesBlaise Cheuteu
 

Andere mochten auch (20)

R - Software Estatistico
R - Software EstatisticoR - Software Estatistico
R - Software Estatistico
 
My first Beamer slide using Emacs org mode
My first Beamer slide using Emacs org mode My first Beamer slide using Emacs org mode
My first Beamer slide using Emacs org mode
 
Chapter8 pl sql
Chapter8 pl sqlChapter8 pl sql
Chapter8 pl sql
 
Introducing The R Software
Introducing The R Software  Introducing The R Software
Introducing The R Software
 
Advantages of pl sql
Advantages of pl sqlAdvantages of pl sql
Advantages of pl sql
 
Introduction to R for Data Science :: Session 8 [Intro to Text Mining in R, M...
Introduction to R for Data Science :: Session 8 [Intro to Text Mining in R, M...Introduction to R for Data Science :: Session 8 [Intro to Text Mining in R, M...
Introduction to R for Data Science :: Session 8 [Intro to Text Mining in R, M...
 
Data Hacking with RHadoop
Data Hacking with RHadoopData Hacking with RHadoop
Data Hacking with RHadoop
 
OBIEE Answers Vs Data Visualization: A Cage Match
OBIEE Answers Vs Data Visualization: A Cage MatchOBIEE Answers Vs Data Visualization: A Cage Match
OBIEE Answers Vs Data Visualization: A Cage Match
 
Diffrence between dbms and rdbms
Diffrence between dbms and rdbmsDiffrence between dbms and rdbms
Diffrence between dbms and rdbms
 
Excel/R
Excel/RExcel/R
Excel/R
 
functional dependencies with example
functional dependencies with examplefunctional dependencies with example
functional dependencies with example
 
Accessing Databases from R
Accessing Databases from RAccessing Databases from R
Accessing Databases from R
 
Applications of R (DataWeek 2014)
Applications of R (DataWeek 2014)Applications of R (DataWeek 2014)
Applications of R (DataWeek 2014)
 
Hp distributed R User Guide
Hp distributed R User GuideHp distributed R User Guide
Hp distributed R User Guide
 
pl/sql online Training|sql online Training | iTeknowledge
pl/sql online Training|sql online Training | iTeknowledgepl/sql online Training|sql online Training | iTeknowledge
pl/sql online Training|sql online Training | iTeknowledge
 
R + Hadoop = Big Data Analytics. How Revolution Analytics' RHadoop Project Al...
R + Hadoop = Big Data Analytics. How Revolution Analytics' RHadoop Project Al...R + Hadoop = Big Data Analytics. How Revolution Analytics' RHadoop Project Al...
R + Hadoop = Big Data Analytics. How Revolution Analytics' RHadoop Project Al...
 
Tapping the Data Deluge with R
Tapping the Data Deluge with RTapping the Data Deluge with R
Tapping the Data Deluge with R
 
Data profiling-best-practices
Data profiling-best-practicesData profiling-best-practices
Data profiling-best-practices
 
Big Data Profiling
Big Data Profiling Big Data Profiling
Big Data Profiling
 
Testing of hypothesis case study
Testing of hypothesis case study Testing of hypothesis case study
Testing of hypothesis case study
 

Ähnlich wie R crash course

R programming language
R programming languageR programming language
R programming languageKeerti Verma
 
Introduction to R and R Studio
Introduction to R and R StudioIntroduction to R and R Studio
Introduction to R and R StudioRupak Roy
 
How to get started with R programming
How to get started with R programmingHow to get started with R programming
How to get started with R programmingRamon Salazar
 
R programming for psychometrics
R programming for psychometricsR programming for psychometrics
R programming for psychometricsDiane Talley
 
How to use R easily as GIS tools!
How to use R easily as GIS tools!How to use R easily as GIS tools!
How to use R easily as GIS tools!Omar F. Althuwaynee
 
R programming Language , Rahul Singh
R programming Language , Rahul SinghR programming Language , Rahul Singh
R programming Language , Rahul SinghRavi Basil
 
R as supporting tool for analytics and simulation
R as supporting tool for analytics and simulationR as supporting tool for analytics and simulation
R as supporting tool for analytics and simulationAlvaro Gil
 
2 it unit-1 start learning r
2 it   unit-1 start learning r2 it   unit-1 start learning r
2 it unit-1 start learning rNetaji Gandi
 
R programming advantages and disadvantages
R programming advantages and disadvantagesR programming advantages and disadvantages
R programming advantages and disadvantagesPrwaTech
 
The Statistical Significance of &quot;R&quot;
The Statistical Significance of &quot;R&quot;The Statistical Significance of &quot;R&quot;
The Statistical Significance of &quot;R&quot;ppvora
 
Introduction into R for historians (part 1: introduction)
Introduction into R for historians (part 1: introduction)Introduction into R for historians (part 1: introduction)
Introduction into R for historians (part 1: introduction)Richard Zijdeman
 

Ähnlich wie R crash course (20)

R programming
R programmingR programming
R programming
 
R programming
R programmingR programming
R programming
 
R programming language
R programming languageR programming language
R programming language
 
Reason To learn & use r
Reason To learn & use rReason To learn & use r
Reason To learn & use r
 
R programming
R programmingR programming
R programming
 
Introduction to R and R Studio
Introduction to R and R StudioIntroduction to R and R Studio
Introduction to R and R Studio
 
Basic introduction into R
Basic introduction into RBasic introduction into R
Basic introduction into R
 
R presentation
R presentationR presentation
R presentation
 
How to get started with R programming
How to get started with R programmingHow to get started with R programming
How to get started with R programming
 
R programming for psychometrics
R programming for psychometricsR programming for psychometrics
R programming for psychometrics
 
How to use R easily as GIS tools!
How to use R easily as GIS tools!How to use R easily as GIS tools!
How to use R easily as GIS tools!
 
R programming Language , Rahul Singh
R programming Language , Rahul SinghR programming Language , Rahul Singh
R programming Language , Rahul Singh
 
R as supporting tool for analytics and simulation
R as supporting tool for analytics and simulationR as supporting tool for analytics and simulation
R as supporting tool for analytics and simulation
 
2 it unit-1 start learning r
2 it   unit-1 start learning r2 it   unit-1 start learning r
2 it unit-1 start learning r
 
UNIT-1 Start Learning R.pdf
UNIT-1 Start Learning R.pdfUNIT-1 Start Learning R.pdf
UNIT-1 Start Learning R.pdf
 
R ext world/ useR! Kiev
R ext world/ useR!  KievR ext world/ useR!  Kiev
R ext world/ useR! Kiev
 
R programming advantages and disadvantages
R programming advantages and disadvantagesR programming advantages and disadvantages
R programming advantages and disadvantages
 
The Statistical Significance of &quot;R&quot;
The Statistical Significance of &quot;R&quot;The Statistical Significance of &quot;R&quot;
The Statistical Significance of &quot;R&quot;
 
Introduction into R for historians (part 1: introduction)
Introduction into R for historians (part 1: introduction)Introduction into R for historians (part 1: introduction)
Introduction into R for historians (part 1: introduction)
 
R Data Analysis Software
R Data Analysis SoftwareR Data Analysis Software
R Data Analysis Software
 

Mehr von Tomislav Hengl

Introducing GSIF (seminar at Lamont campus)
Introducing GSIF (seminar at Lamont campus)Introducing GSIF (seminar at Lamont campus)
Introducing GSIF (seminar at Lamont campus)Tomislav Hengl
 
Poster "Global Soil Information Facilities"
Poster "Global Soil Information Facilities"Poster "Global Soil Information Facilities"
Poster "Global Soil Information Facilities"Tomislav Hengl
 
A statistical assessment of GDEM using LiDAR data
A statistical assessment of GDEM using LiDAR dataA statistical assessment of GDEM using LiDAR data
A statistical assessment of GDEM using LiDAR dataTomislav Hengl
 
Hengl & Reuter poster at Geomorphometry.org/2011
Hengl & Reuter poster at Geomorphometry.org/2011Hengl & Reuter poster at Geomorphometry.org/2011
Hengl & Reuter poster at Geomorphometry.org/2011Tomislav Hengl
 
Open Soil Profiles - testbed data portal for storing soil profile data
Open Soil Profiles - testbed data portal for storing soil profile dataOpen Soil Profiles - testbed data portal for storing soil profile data
Open Soil Profiles - testbed data portal for storing soil profile dataTomislav Hengl
 
Worldgrids.org: building global covariates for automated mapping
Worldgrids.org: building global covariates for automated mappingWorldgrids.org: building global covariates for automated mapping
Worldgrids.org: building global covariates for automated mappingTomislav Hengl
 
Space-time data workshop at IfGI
Space-time data workshop at IfGISpace-time data workshop at IfGI
Space-time data workshop at IfGITomislav Hengl
 
Global soilmap at_afsis_hengl
Global soilmap at_afsis_henglGlobal soilmap at_afsis_hengl
Global soilmap at_afsis_henglTomislav Hengl
 
Spatial interpolation comparison
Spatial interpolation comparisonSpatial interpolation comparison
Spatial interpolation comparisonTomislav Hengl
 
DSM training - preparing auxiliary data
DSM training - preparing auxiliary dataDSM training - preparing auxiliary data
DSM training - preparing auxiliary dataTomislav Hengl
 

Mehr von Tomislav Hengl (14)

Introducing GSIF (seminar at Lamont campus)
Introducing GSIF (seminar at Lamont campus)Introducing GSIF (seminar at Lamont campus)
Introducing GSIF (seminar at Lamont campus)
 
Poster "Global Soil Information Facilities"
Poster "Global Soil Information Facilities"Poster "Global Soil Information Facilities"
Poster "Global Soil Information Facilities"
 
A statistical assessment of GDEM using LiDAR data
A statistical assessment of GDEM using LiDAR dataA statistical assessment of GDEM using LiDAR data
A statistical assessment of GDEM using LiDAR data
 
Hengl & Reuter poster at Geomorphometry.org/2011
Hengl & Reuter poster at Geomorphometry.org/2011Hengl & Reuter poster at Geomorphometry.org/2011
Hengl & Reuter poster at Geomorphometry.org/2011
 
SAGA GIS 2.0.7
SAGA GIS 2.0.7SAGA GIS 2.0.7
SAGA GIS 2.0.7
 
GSIF utilities
GSIF utilitiesGSIF utilities
GSIF utilities
 
Open Soil Profiles - testbed data portal for storing soil profile data
Open Soil Profiles - testbed data portal for storing soil profile dataOpen Soil Profiles - testbed data portal for storing soil profile data
Open Soil Profiles - testbed data portal for storing soil profile data
 
Drupal course hengl
Drupal course henglDrupal course hengl
Drupal course hengl
 
Worldgrids.org: building global covariates for automated mapping
Worldgrids.org: building global covariates for automated mappingWorldgrids.org: building global covariates for automated mapping
Worldgrids.org: building global covariates for automated mapping
 
Space-time data workshop at IfGI
Space-time data workshop at IfGISpace-time data workshop at IfGI
Space-time data workshop at IfGI
 
Global soilmap at_afsis_hengl
Global soilmap at_afsis_henglGlobal soilmap at_afsis_hengl
Global soilmap at_afsis_hengl
 
Spatial interpolation comparison
Spatial interpolation comparisonSpatial interpolation comparison
Spatial interpolation comparison
 
DSM training - preparing auxiliary data
DSM training - preparing auxiliary dataDSM training - preparing auxiliary data
DSM training - preparing auxiliary data
 
Latex crash course
Latex crash courseLatex crash course
Latex crash course
 

Kürzlich hochgeladen

Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxGrade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxkarenfajardo43
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationdeepaannamalai16
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Association for Project Management
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfPrerana Jadhav
 
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxMan or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxDhatriParmar
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operationalssuser3e220a
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQ-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQuiz Club NITW
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Projectjordimapav
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataBabyAnnMotar
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Multi Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleMulti Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleCeline George
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...DhatriParmar
 

Kürzlich hochgeladen (20)

Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxGrade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentation
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdf
 
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxMan or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operational
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQ-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Project
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped data
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Multi Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleMulti Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP Module
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
 

R crash course

  • 1. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature R crash course (for people who pick up new methods/tools quickly and have a high motivation to learn) T. Hengl1 & R.S. Bivand2 1Instituut voor Biodiversiteit en Ecosysteem Dynamica Universiteit van Amsterdam 2Department of Economics Norwegian School of Economics and Business administration June 19, 2010
  • 2. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Outline 1 Overview Course programme Why R? Software installation 2 Scripting in R Do’s and don’ts R code editors 3 Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth 4 Literature
  • 3. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Programme Installation and first (baby) steps (intro.R). Building, running and editing models in R. Working with spatial data.
  • 4. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Crash course A“crash course”is a compressed version of a training course for people that already have full agendas. It is really intended for people who pick up new methods/tools quickly and have a high motivation to learn (PhD students?). This means no long questions, no going back, no long discussion, no complains about the speed/programme of the course. . . and of course: no promises that you will manage to learn R in such a short time.
  • 5. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature The course programme Basic concepts (self-study) R basic and add-on packages; R syntax; R objects and ’methods’; R FAQs; getting help and the most important literature; Scripting in R data management; creating and debugging scripts (scripting editors: Tinn-R); automating analysis — making functions and packages; publication quality outputs (using R+Sweave); Advanced topics GDAL and R; spatial classes and packages; calling external applications from R (SAGA GIS, FWTools, Python, Matlab; export of maps to Google Earth;
  • 6. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Outline 1 Overview Course programme Why R? Software installation 2 Scripting in R Do’s and don’ts R code editors 3 Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth 4 Literature
  • 7. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Getting the right motivation (inspiration) What is R, and why should you invest time to learn it? What can it do? (and what it can’t do?) How does the R community works (what are its shared principles)? Is R suited for spatio-temporal data analysis?
  • 8. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Some important assumptions R is (increasingly) sexy. R is hell. You are all beginners (who need a gentle intro). You are non-statisticians / computer scientists. I learned R myself. If I can do it, you can do it too.
  • 9. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Some important assumptions R is (increasingly) sexy. R is hell. You are all beginners (who need a gentle intro). You are non-statisticians / computer scientists. I learned R myself. If I can do it, you can do it too.
  • 10. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Some important assumptions R is (increasingly) sexy. R is hell. You are all beginners (who need a gentle intro). You are non-statisticians / computer scientists. I learned R myself. If I can do it, you can do it too.
  • 11. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Some important assumptions R is (increasingly) sexy. R is hell. You are all beginners (who need a gentle intro). You are non-statisticians / computer scientists. I learned R myself. If I can do it, you can do it too.
  • 12. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Some important assumptions R is (increasingly) sexy. R is hell. You are all beginners (who need a gentle intro). You are non-statisticians / computer scientists. I learned R myself. If I can do it, you can do it too.
  • 13. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature What is R? the open source implementation of the S language for statistical computing created by created by Ross Ihaka and Robert Gentleman (now maintained by the R Development Core Team); why R?: the name“R”was selected for two reasons: (1) precedence —“R”is a letter before“S”, and (2) coincidence — both of the creators’ names start with a letter“R”; it is a computer language developed to simplify statistical computing/programming; it offers many contributed packages, technical documents, demos and examples; widely recognized as one of the fastest growing and most comprehensive statistical computing tools; it is a movement;
  • 14. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature What is R? the open source implementation of the S language for statistical computing created by created by Ross Ihaka and Robert Gentleman (now maintained by the R Development Core Team); why R?: the name“R”was selected for two reasons: (1) precedence —“R”is a letter before“S”, and (2) coincidence — both of the creators’ names start with a letter“R”; it is a computer language developed to simplify statistical computing/programming; it offers many contributed packages, technical documents, demos and examples; widely recognized as one of the fastest growing and most comprehensive statistical computing tools; it is a movement;
  • 15. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature What is R? the open source implementation of the S language for statistical computing created by created by Ross Ihaka and Robert Gentleman (now maintained by the R Development Core Team); why R?: the name“R”was selected for two reasons: (1) precedence —“R”is a letter before“S”, and (2) coincidence — both of the creators’ names start with a letter“R”; it is a computer language developed to simplify statistical computing/programming; it offers many contributed packages, technical documents, demos and examples; widely recognized as one of the fastest growing and most comprehensive statistical computing tools; it is a movement;
  • 16. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature What is R? the open source implementation of the S language for statistical computing created by created by Ross Ihaka and Robert Gentleman (now maintained by the R Development Core Team); why R?: the name“R”was selected for two reasons: (1) precedence —“R”is a letter before“S”, and (2) coincidence — both of the creators’ names start with a letter“R”; it is a computer language developed to simplify statistical computing/programming; it offers many contributed packages, technical documents, demos and examples; widely recognized as one of the fastest growing and most comprehensive statistical computing tools; it is a movement;
  • 17. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature What is R? the open source implementation of the S language for statistical computing created by created by Ross Ihaka and Robert Gentleman (now maintained by the R Development Core Team); why R?: the name“R”was selected for two reasons: (1) precedence —“R”is a letter before“S”, and (2) coincidence — both of the creators’ names start with a letter“R”; it is a computer language developed to simplify statistical computing/programming; it offers many contributed packages, technical documents, demos and examples; widely recognized as one of the fastest growing and most comprehensive statistical computing tools; it is a movement;
  • 18. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature What is R? the open source implementation of the S language for statistical computing created by created by Ross Ihaka and Robert Gentleman (now maintained by the R Development Core Team); why R?: the name“R”was selected for two reasons: (1) precedence —“R”is a letter before“S”, and (2) coincidence — both of the creators’ names start with a letter“R”; it is a computer language developed to simplify statistical computing/programming; it offers many contributed packages, technical documents, demos and examples; widely recognized as one of the fastest growing and most comprehensive statistical computing tools; it is a movement;
  • 19. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature R is“sexy”
  • 20. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Quote “R has really become the second language for people coming out of grad school now, and there’s an amazing amount of code being written for it.” Max Kuhn
  • 21. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature What it is NOT it’s not a software with GUI and point-and-click control; there are practically no data analysis wizards; it’s not an interactive system; it comes with no warranties (but so does the commercial software too!!); there is practically no formal support; however. . .
  • 22. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature What it is NOT it’s not a software with GUI and point-and-click control; there are practically no data analysis wizards; it’s not an interactive system; it comes with no warranties (but so does the commercial software too!!); there is practically no formal support; however. . .
  • 23. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature What it is NOT it’s not a software with GUI and point-and-click control; there are practically no data analysis wizards; it’s not an interactive system; it comes with no warranties (but so does the commercial software too!!); there is practically no formal support; however. . .
  • 24. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature What it is NOT it’s not a software with GUI and point-and-click control; there are practically no data analysis wizards; it’s not an interactive system; it comes with no warranties (but so does the commercial software too!!); there is practically no formal support; however. . .
  • 25. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature What it is NOT it’s not a software with GUI and point-and-click control; there are practically no data analysis wizards; it’s not an interactive system; it comes with no warranties (but so does the commercial software too!!); there is practically no formal support; however. . .
  • 26. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature What it is NOT it’s not a software with GUI and point-and-click control; there are practically no data analysis wizards; it’s not an interactive system; it comes with no warranties (but so does the commercial software too!!); there is practically no formal support; however. . .
  • 27. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Why make scripts? It’s easy to use: “Because S (and its implementation R) is a well-developed, simple and effective programming language which includes conditionals, loops, user-defined recursive functions and input and output facilities, existing functions can be modified.” In R we all become programmers (but much faster than with C++ or Java). The basic approach to using R is to generate scripts that define the data processing steps (workflows?). Documenting the analysis process is a“good thing”, so programming scripts are not just a burden, certainly for users doing original research and repetitive work, arguably for student classes too. Point-and-click operations are for amateurs.
  • 28. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Why make scripts? It’s easy to use: “Because S (and its implementation R) is a well-developed, simple and effective programming language which includes conditionals, loops, user-defined recursive functions and input and output facilities, existing functions can be modified.” In R we all become programmers (but much faster than with C++ or Java). The basic approach to using R is to generate scripts that define the data processing steps (workflows?). Documenting the analysis process is a“good thing”, so programming scripts are not just a burden, certainly for users doing original research and repetitive work, arguably for student classes too. Point-and-click operations are for amateurs.
  • 29. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Why make scripts? It’s easy to use: “Because S (and its implementation R) is a well-developed, simple and effective programming language which includes conditionals, loops, user-defined recursive functions and input and output facilities, existing functions can be modified.” In R we all become programmers (but much faster than with C++ or Java). The basic approach to using R is to generate scripts that define the data processing steps (workflows?). Documenting the analysis process is a“good thing”, so programming scripts are not just a burden, certainly for users doing original research and repetitive work, arguably for student classes too. Point-and-click operations are for amateurs.
  • 30. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Why make scripts? It’s easy to use: “Because S (and its implementation R) is a well-developed, simple and effective programming language which includes conditionals, loops, user-defined recursive functions and input and output facilities, existing functions can be modified.” In R we all become programmers (but much faster than with C++ or Java). The basic approach to using R is to generate scripts that define the data processing steps (workflows?). Documenting the analysis process is a“good thing”, so programming scripts are not just a burden, certainly for users doing original research and repetitive work, arguably for student classes too. Point-and-click operations are for amateurs.
  • 31. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Do you speak R? After some time you basically discovered that most of the things you want to do, you can do in R, the only question is how. Well, first, you have to learn to how to speak’n’write R.
  • 32. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Why NOT Matlab? R and Matlab are in fact very similar, except. . . : (almost) everything you do in Matlab, you can do in R; R can be used to write homework (for Matlab you need a computer lab with software licences); “R gradually pushes people towards better programming habits”(Tam´as K. Papp); Matlab has a limited support for processing spatial data (R is better); Contributed packages in R are growing faster (R is better); We are in academia — we shouldn’t be developing toolboxes for some private company but for the people (and for ourselves);
  • 33. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature A bit of history R was first time released in 1997; majority of the development is (still) done by prof. Brian D. Ripley; a the moment (juni 19 2010 10:01), there are 2387 contributed packages! according to Google trends, R-project.org has a community of about 200–350k active users; in 2003, a group of researchers (International Workshop on Distributed Statistical Computing) decided to add Spatial functionality to R; . . . now is time to use it more broadly (MSc level and PhD level modules, projects, reports and scientific documents);
  • 34. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Quote “Once methodological problems start being perceived or even defined in terms of what one’s favorite software does well, then the software has stopped being a tool, and has become a crutch, and at worse a shackle.” Simon Jackman
  • 35. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature The ASDA(R)-book.org
  • 36. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature The ASDA(R) team
  • 37. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature A Practical Guide to Geostatistical Mapping
  • 38. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Quote “I created Quick-R for one simple reason. I wanted to learn R and I am a teacher at heart. The easiest way for me to learn something is to teach it” Robert I. Kabacoff
  • 39. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Outline 1 Overview Course programme Why R? Software installation 2 Scripting in R Do’s and don’ts R code editors 3 Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth 4 Literature
  • 40. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Software Not all software is required to follow the exercises R v2.11 (Windows OS) including a list of packages; Tinn-R v2.3 (code editor); Optional: FWTools v2.4 — a list of utilities to handle spatial data; SAGA GIS v2.0.4 — a light GIS excellent for educational purposes.
  • 41. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Installing the add-on packages > install.packages("ctv") > library(ctv) > install.views("Spatial") This will install all connected packages listed at R views Spatial.
  • 42. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Check your installation > Sys.getenv(c("OS", "COMPUTERNAME", "R_HOME", "R_LIBS_USER", + "PROCESSOR_IDENTIFIER")) OS "Windows_NT" COMPUTERNAME "PC-IBED193" R_HOME "C:PROGRA~1RR-210~1.1" R_LIBS_USER "n:/R/win-library/2.10" PROCESSOR_IDENTIFIER "x86 Family 6 Model 15 Stepping 6, GenuineIntel"
  • 43. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Outline 1 Overview Course programme Why R? Software installation 2 Scripting in R Do’s and don’ts R code editors 3 Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth 4 Literature
  • 44. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Making friends with R 1 Use script editors such as as TINN-R or JGR (syntax highlighting, wrapping, search/replace etc.). 2 The best way to learn R is to look at the existing scripts, then extend: Graphical Manual/Addicted to R — if you prefer to explore examples graphically; Teach-your-self books e.g.“Statistics with R”or“An Introduction to R”;“Introduction to R for ITC students” Quick-R and/or R by example; 3 If your R script does not work, do not break your head, try to get help: local installation: > help.search("kriging"); R-project: > RSiteSearch("krige dimensions do not match") www: Rseek.org R mailing lists;
  • 45. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Making friends with R 1 Use script editors such as as TINN-R or JGR (syntax highlighting, wrapping, search/replace etc.). 2 The best way to learn R is to look at the existing scripts, then extend: Graphical Manual/Addicted to R — if you prefer to explore examples graphically; Teach-your-self books e.g.“Statistics with R”or“An Introduction to R”;“Introduction to R for ITC students” Quick-R and/or R by example; 3 If your R script does not work, do not break your head, try to get help: local installation: > help.search("kriging"); R-project: > RSiteSearch("krige dimensions do not match") www: Rseek.org R mailing lists;
  • 46. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Making friends with R 1 Use script editors such as as TINN-R or JGR (syntax highlighting, wrapping, search/replace etc.). 2 The best way to learn R is to look at the existing scripts, then extend: Graphical Manual/Addicted to R — if you prefer to explore examples graphically; Teach-your-self books e.g.“Statistics with R”or“An Introduction to R”;“Introduction to R for ITC students” Quick-R and/or R by example; 3 If your R script does not work, do not break your head, try to get help: local installation: > help.search("kriging"); R-project: > RSiteSearch("krige dimensions do not match") www: Rseek.org R mailing lists;
  • 47. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Making friends with R 1 Use script editors such as as TINN-R or JGR (syntax highlighting, wrapping, search/replace etc.). 2 The best way to learn R is to look at the existing scripts, then extend: Graphical Manual/Addicted to R — if you prefer to explore examples graphically; Teach-your-self books e.g.“Statistics with R”or“An Introduction to R”;“Introduction to R for ITC students” Quick-R and/or R by example; 3 If your R script does not work, do not break your head, try to get help: local installation: > help.search("kriging"); R-project: > RSiteSearch("krige dimensions do not match") www: Rseek.org R mailing lists;
  • 48. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Making friends with R 1 Use script editors such as as TINN-R or JGR (syntax highlighting, wrapping, search/replace etc.). 2 The best way to learn R is to look at the existing scripts, then extend: Graphical Manual/Addicted to R — if you prefer to explore examples graphically; Teach-your-self books e.g.“Statistics with R”or“An Introduction to R”;“Introduction to R for ITC students” Quick-R and/or R by example; 3 If your R script does not work, do not break your head, try to get help: local installation: > help.search("kriging"); R-project: > RSiteSearch("krige dimensions do not match") www: Rseek.org R mailing lists;
  • 49. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Making friends with R 1 Use script editors such as as TINN-R or JGR (syntax highlighting, wrapping, search/replace etc.). 2 The best way to learn R is to look at the existing scripts, then extend: Graphical Manual/Addicted to R — if you prefer to explore examples graphically; Teach-your-self books e.g.“Statistics with R”or“An Introduction to R”;“Introduction to R for ITC students” Quick-R and/or R by example; 3 If your R script does not work, do not break your head, try to get help: local installation: > help.search("kriging"); R-project: > RSiteSearch("krige dimensions do not match") www: Rseek.org R mailing lists;
  • 50. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Making friends with R 1 Use script editors such as as TINN-R or JGR (syntax highlighting, wrapping, search/replace etc.). 2 The best way to learn R is to look at the existing scripts, then extend: Graphical Manual/Addicted to R — if you prefer to explore examples graphically; Teach-your-self books e.g.“Statistics with R”or“An Introduction to R”;“Introduction to R for ITC students” Quick-R and/or R by example; 3 If your R script does not work, do not break your head, try to get help: local installation: > help.search("kriging"); R-project: > RSiteSearch("krige dimensions do not match") www: Rseek.org R mailing lists;
  • 51. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Making friends with R 1 Use script editors such as as TINN-R or JGR (syntax highlighting, wrapping, search/replace etc.). 2 The best way to learn R is to look at the existing scripts, then extend: Graphical Manual/Addicted to R — if you prefer to explore examples graphically; Teach-your-self books e.g.“Statistics with R”or“An Introduction to R”;“Introduction to R for ITC students” Quick-R and/or R by example; 3 If your R script does not work, do not break your head, try to get help: local installation: > help.search("kriging"); R-project: > RSiteSearch("krige dimensions do not match") www: Rseek.org R mailing lists;
  • 52. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Making friends with R 1 Use script editors such as as TINN-R or JGR (syntax highlighting, wrapping, search/replace etc.). 2 The best way to learn R is to look at the existing scripts, then extend: Graphical Manual/Addicted to R — if you prefer to explore examples graphically; Teach-your-self books e.g.“Statistics with R”or“An Introduction to R”;“Introduction to R for ITC students” Quick-R and/or R by example; 3 If your R script does not work, do not break your head, try to get help: local installation: > help.search("kriging"); R-project: > RSiteSearch("krige dimensions do not match") www: Rseek.org R mailing lists;
  • 53. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Making friends with R 1 Use script editors such as as TINN-R or JGR (syntax highlighting, wrapping, search/replace etc.). 2 The best way to learn R is to look at the existing scripts, then extend: Graphical Manual/Addicted to R — if you prefer to explore examples graphically; Teach-your-self books e.g.“Statistics with R”or“An Introduction to R”;“Introduction to R for ITC students” Quick-R and/or R by example; 3 If your R script does not work, do not break your head, try to get help: local installation: > help.search("kriging"); R-project: > RSiteSearch("krige dimensions do not match") www: Rseek.org R mailing lists;
  • 54. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Good practice Put comments in script (after #). Add some meta-information at the beginning of your script. Once you tested your script and saw that it works, tidy-up the code. Place the input data on-line (database) so you can communicate only the script.
  • 55. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature R mailing lists: Do’s and Don’ts! Do’s: If you have not done so already, read the R posting guide. Use the existing pre-installed data sets (come together with a certain package) to describe your problem; link your problem to some existing problems. Acknowledge the work (time spent) other people do to help you. You can submit not only the problems you discover but also the information that you think is interesting for the community. Don’ts: Do not send poorly formulated questions. Do not send too much. Complaining to a mailing list about what frustrates you about R makes no sense. You are requesting that somebody does a work for you that you could do yourself!
  • 56. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Outline 1 Overview Course programme Why R? Software installation 2 Scripting in R Do’s and don’ts R code editors 3 Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth 4 Literature
  • 57. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Tinn-R
  • 58. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature JaGuaR
  • 59. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Outline 1 Overview Course programme Why R? Software installation 2 Scripting in R Do’s and don’ts R code editors 3 Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth 4 Literature
  • 60. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Spatial objects An advantage of R (as compared to e.g. Matlab) is that you can create your own formats and structures for data. But if there are too many formats you can easily get lots. In addition, we want to have smooth links to external formats (R is open!). To reduce this problem, Bivand et al. (2008) developed new-style classes to represent spatial data.
  • 61. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Spatial class The foundation object is the Spatial class, with just two basic slots (new-style S classes have pre-defined components called slots): a bounding box — mostly used for setting up plots; a CRS class object — defining the coordinate reference system, and may be set to CRS(as.character(NA)); Operations on Spatial* objects should update or copy these values to the new Spatial* objects being created. The most basic spatial data object is a point, which may have 2 or 3 dimensions.
  • 62. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Spatial classes for point features: SpatialPoints; SpatialPointsDataFrame; for line features: SpatialLines, SpatialLinesDataFrame; polygons: SpatialPolygons, SpatialPolygonsDataFrame; rasters: SpatialPixels, SpatialPixelsDataFrame, SpatialGrid, SpatialGridDataFrame;
  • 63. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature SpatialPoints > library(sp) > data(meuse) > coords <- SpatialPoints(meuse[, c("x", "y")]) > summary(coords) Object of class SpatialPoints Coordinates: min max x 178605 181390 y 329714 333611 Is projected: NA proj4string : [NA] Number of points: 155
  • 64. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature SpatialPointsDataFrame We can add the tabular data to make a SpatialPointsDataFrame object: > meuse1 <- SpatialPointsDataFrame(coords, meuse) > str(meuse1, max.level = 2) Formal class 'SpatialPointsDataFrame' [package "sp"] with 5 slots ..@ data :'data.frame': 155 obs. of 14 variables: ..@ coords.nrs : num(0) ..@ coords : num [1:155, 1:2] 181072 181025 181165 ... .. ..- attr(*, "dimnames")=List of 2 ..@ bbox : num [1:2, 1:2] 178605 329714 181390 333611 .. ..- attr(*, "dimnames")=List of 2 ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slots
  • 65. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Point features ments Spatial points classes and their slots coords Spatial coords.nrs data SpatialPoints bbox proj4string SpatialPointsDataFrame data.frame Spatial SpatialPoints Spatial lines and polygons
  • 66. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Line/polygon features dge m a ns Spatial Polygons classes and slots coords Spatial lines plotOrder Spatial polygons bbox proj4string Polygon coords labpt area hole ringDir LineLines ID Polygons plotOrder labpt ID area SpatialLines Spatial SpatialPolygons Lines Polygons
  • 67. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Grids e bank he data m the Spatial grid and pixels classes and their slots data SpatialPixels SpatialGrid data grid grid.index SpatialPoints grid grid.index SpatialPoints cellcentre.offset cellsize cells.dim coords Spatial bbox proj4string data.frame Spatial GridTopology SpatialPoints SpatialGridDataFrame SpatialGrid SpatialPixels SpatialPixelsDataFrame Spatial classes provided by sp
  • 68. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Outline 1 Overview Course programme Why R? Software installation 2 Scripting in R Do’s and don’ts R code editors 3 Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth 4 Literature
  • 69. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Basic methods spplot — plotting of spatial objects (maps); spsample — sample points from a set of polygons, on a set of lines or from a gridded area; bbox — get the bounding box; proj4string — get or set the projection (coordinate reference system); coordinates — set or retrieve coordinates; spTransform — transform coordinates from one CRS to another; overlay — combine two different spatial objects;
  • 70. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Plotting a SpatialPoints object > plot(as(meuse1, "Spatial"), axes = TRUE) > plot(meuse1, add = TRUE) > plot(meuse1[meuse1$ffreq == 1, ], col = "green", add = TRUE) 178000 179000 180000 181000 182000 330000331000332000333000
  • 71. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Combining statistical and GIS operations Because the Spatial*DataFrame family objects behave in most cases like data frames, most of what we are used to doing with standard data frames just works (but no merge, etc., yet). These objects are very similar to typical representations of the same kinds of objects in geographical information systems, so they do not suit spatial data that is not geographical (like medical imaging) as such. Because now sp classes for GIS data exits, this opens the door for fusing GIS and statistical operations (this has not been possible in e.g. 2002).
  • 72. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Spatial packages R now offers a range of contributed packages in spatial statistics and increasing awareness of the importance of spatial data analysis in the broader community. Current contributed packages with spatial applications: point patterns: spatstat, VR:spatial, splancs; geostatistics: gstat, geoR, geoRglm, fields, spBayes, RandomFields, VR:spatial, sgeostat, vardiag; lattice/area data: spdep, DCluster, spgwr, ade4; links to GIS: rgdal, spgrass, RPy, RSAGA;
  • 73. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Let’s create spatial objects! We can create spatial objects from scratch! For example a DEM: > dem <- expand.grid(x = seq(100, 600, 100), y = seq(100, + 600, 100)) > dem$Z <- as.vector(c(23, 24, 34, 38, 45, 51, 24, 20, + 20, 28, 18, 49, 22, 20, 19, 14, 38, 45, 19, 15, 13, + 21, 23, 25, 14, 11, 18, 11, 18, 19, 10, 16, 23, 16, + 9, 6)) > gridded(dem) <- ~x + y > dem <- as(dem, "SpatialGridDataFrame") > str(dem)
  • 74. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature A small DEM > dem.plt <- spplot(dem[1], main = "DEM", scales = list(draw = FALSE), + col.regions = topo.colors(25)) > print(dem.plt) > writeGDAL(dem, "dem6.sdat", "SAGA") DEM 10 20 30 40 50
  • 75. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Outline 1 Overview Course programme Why R? Software installation 2 Scripting in R Do’s and don’ts R code editors 3 Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth 4 Literature
  • 76. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Controlling SAGA from R > library(RSAGA) > rsaga.env() $workspace [1] "." $cmd [1] "saga_cmd.exe" $path [1] "C:/PROGRA~1/R/R-210~1.1/library/RSAGA/saga_vc" $modules [1] "C:/PROGRA~1/R/R-210~1.1/library/RSAGA/saga_vc/modules"
  • 77. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Getting list of modules > rsaga.get.modules("ta_channels") $ta_channels code name interactive 1 0 Channel Network FALSE 2 1 Watershed Basins FALSE 3 2 Watershed Basins (extended) FALSE 4 3 Vertical Distance to Channel Network FALSE 5 4 Overland Flow Distance to Channel Network FALSE 6 5 D8 Flow Analysis FALSE 7 6 Strahler Order FALSE
  • 78. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Run stream extraction > rsaga.geoprocessor(lib = "ta_channels", module = 5, param = list(DEM = " + DIRECTION = "channels.sgrd", CONNECTION = "route.sgrd", + NETWORK = "channels.shp")) SAGA CMD 2.0.4 library path: C:/PROGRA~1/R/R-210~1.1/library/RSAGA/... library name: ta_channels module name : D8 Flow Analysis author : (c) 2003 by O.Conrad Load grid: dem6.sgrd... ready Parameters Grid system: 100; 6x 6y; 100x 100y DEM: dem6 Flow Direction: Flow Direction Flow Connectivity: Flow Connectivity Flow Network: Flow Network Minimum Connectivity: 0 ...
  • 79. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Read back to R > dem$route <- readGDAL("route.sdat")$band1 route.sdat has GDAL driver SAGA and has 6 rows and 6 columns > channels <- readOGR("channels.shp", "channels") OGR data source with driver: ESRI Shapefile Source: "channels.shp", layer: "channels" with 32 features and 2 fields Feature type: wkbLineString with 2 dimensions
  • 80. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Plot the final result > dem.plt <- spplot(dem[1], main = "DEM", col.regions = topo.colors(25)) > channels.plt <- spplot(dem[2], col.regions = rev(gray(0:20/20)), + main = "Flow connectivity", sp.layout = list("sp.lines", + channels, col = "red")) > print(dem.plt, split = c(1, 1, 2, 1), more = T) > print(channels.plt, split = c(2, 1, 2, 1), more = F) DEM 10 20 30 40 50 Flow connectivity 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0
  • 81. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Outline 1 Overview Course programme Why R? Software installation 2 Scripting in R Do’s and don’ts R code editors 3 Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth 4 Literature
  • 82. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Preparing FWTools There is still no package to control FWTools from R, but we can simply send command lines using the system command. Before we can use FWTools from R, we need to locate it on our PC: > gdalwarp <- gsub("/", "", dir(path="C:/PROGRA~2/FWTOOL~1.7", + pattern="gdalwarp.exe", recursive=TRUE, full.names=TRUE)) > gdalwarp [1] "C:PROGRA~2FWTOOL~1.7bingdalwarp.exe" > workd <- paste(gsub("/", "", getwd()), "", sep="")
  • 83. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature MODIS data Now we can download some GIS data from web: > MOD12Q1 <- "ftp://anonymous:test@e4ftl01u.ecs.nasa.gov/ + MOLT/MOD12Q1.004/2004.01.01/" > download.file(paste(MOD12Q1, + "MOD12Q1.A2004001.h18v03.004.2006117173748.hdf", sep=""), + destfile=paste(getwd(), + "MOD12Q1.A2004001.h18v03.004.2006117173748.hdf", sep="/"), + mode='wb', method='wget') Resolving e4ftl01u.ecs.nasa.gov... 152.61.4.83 Connecting to e4ftl01u.ecs.nasa.gov|152.61.4.83|:21... connected. Logging in as anonymous ... Logged in! ==> SYST ... done. ==> PWD ... done. ==> TYPE I ... done. ==> CWD /MOLT/MOD12Q1.004/2004.01.01 ... done. ==> SIZE MOD12Q1.A2004001.h18v03.004.2006117173748.hdf ... 23165983 ==> PASV ... done. ==> RETR MOD12Q1.A2004... done. Length: 23165983 (22M) 0K .......... .......... 0% 64.9K 5m48s ... 22550K .......... .......... 99% 501K 0s 22600K .......... 100% 503K=65s
  • 84. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Reprojecting grids We can reproject/resample the map to our local coordinate system using the gdalwarp functionality (this combines several processing steps in one function): > NL.prj <- "+proj=sterea +lat_0=52.15616055555555 + +lon_0=5.38763888888889 +k=0.999908 +x_0=155000 + +y_0=463000 +ellps=bessel +units=m +no_defs + +towgs84=565.237,50.0087,465.658, + -0.406857,0.350733,-1.87035,4.0812" > system(paste(gdalwarp, " HDF4_EOS:EOS_GRID:"", workd, + "MOD12Q1.A2004001.h18v03.004.2006117173748.hdf" + :MOD12Q1:Land_Cover_Type_1 -t_srs "", NL.prj, "" + IGBP2004NL.tif -r near -te 0 300000 280000 625000 + -tr 500 500", sep="")) Creating output file that is 560P x 650L. Processing input file HDF4_EOS:EOS_GRID:MOD12Q1.A2004001... Using internal nodata values (eg. 255) for image HDF4_EOS:EOS_... 0...10...20...30...40...50...60...70...80...90...100 - done.
  • 85. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Plot the final result In this case we have produced a MODIS-based land cover map for the whole Netherlands in resolution of 500 m (in local coordinate system).
  • 86. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Outline 1 Overview Course programme Why R? Software installation 2 Scripting in R Do’s and don’ts R code editors 3 Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth 4 Literature
  • 87. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Writing spatial data to KML There are two possibilities to export maps to KML: (a) using existing packages, and (b) by writing KML files “by-hand”. To export point or line features to KML, use the writeOGR method that is available in R package rgdal. More flexible way to writing KML files is by using loops.
  • 88. R crash course T. Hengl & R.S. Bivand Overview Course programme Why R? Software installation Scripting in R Do’s and don’ts R code editors Working with spatial data Spatial classes Spatial methods R+SAGA R+FWTools Export to Google Earth Literature Literature Bivand, R., Pebesma, E., Rubio, V., 2008. Applied Spatial Data Analysis with R. Use R Series, Springer, Heidelberg, 378 p. Hengl, T., 2009. A Practical Guide to Geostatistical Mapping, 2nd edition. University of Amsterdam, 291 p. ISBN 978-90-9024981-0. Kabacoff, R.I., 2009. Data Analysis and Graphics with R. Manning publications, 375 p. Zuur, A. F., Ieno, E. N., Meesters, E. H. W. G., 2009. A Beginner’s Guide to R. Springer, Use R series, 228 p.