pengenalan r untuk data spasial - ipb university spatial statistics/p1- pengenalan r...

39
PENGENALAN R UNTUK DATA SPASIAL Praktikum 1 | Statistika Spasial [email protected]

Upload: others

Post on 14-Jan-2020

17 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Pengenalan R untuk data spasial - IPB University Spatial Statistics/P1- Pengenalan R untuk...INSTALLING R AND RSTUDIO If you do not have R and RStudio on your computer, proceed as

PENGENALAN R UNTUK DATA SPASIAL

Praktikum 1 | Statistika Spasial

[email protected]

Page 2: Pengenalan R untuk data spasial - IPB University Spatial Statistics/P1- Pengenalan R untuk...INSTALLING R AND RSTUDIO If you do not have R and RStudio on your computer, proceed as

INSTALLING R AND RSTUDIO

If you do not have R and RStudio on your computer, proceed as follows:

1. Download base R for your operating system from https://cran.r-project. org.

2. Install it on your system.

3. Download RStudio desktop version for your operating system from https://www.rstudio.com/products/RStudio/.

4. Install it on your system.

Page 3: Pengenalan R untuk data spasial - IPB University Spatial Statistics/P1- Pengenalan R untuk...INSTALLING R AND RSTUDIO If you do not have R and RStudio on your computer, proceed as
Page 4: Pengenalan R untuk data spasial - IPB University Spatial Statistics/P1- Pengenalan R untuk...INSTALLING R AND RSTUDIO If you do not have R and RStudio on your computer, proceed as

INSTALLING PACKAGES

Jalankan R

Jika terhubung ke internet: install.packages(“namapackage”)

install.packages(c("sp", "gstat"))

Jika sudah download binary (*.zip): install.packages(“drive:/namafile.zip”,repos=NULL)

atau melalui menu: Packages > Install packages(s) from local files…

Page 5: Pengenalan R untuk data spasial - IPB University Spatial Statistics/P1- Pengenalan R untuk...INSTALLING R AND RSTUDIO If you do not have R and RStudio on your computer, proceed as

FIRST INTERACTION WITH R

Page 6: Pengenalan R untuk data spasial - IPB University Spatial Statistics/P1- Pengenalan R untuk...INSTALLING R AND RSTUDIO If you do not have R and RStudio on your computer, proceed as

FIRST INTERACTION WITH R

library(sp)

library(gstat)

Page 7: Pengenalan R untuk data spasial - IPB University Spatial Statistics/P1- Pengenalan R untuk...INSTALLING R AND RSTUDIO If you do not have R and RStudio on your computer, proceed as
Page 8: Pengenalan R untuk data spasial - IPB University Spatial Statistics/P1- Pengenalan R untuk...INSTALLING R AND RSTUDIO If you do not have R and RStudio on your computer, proceed as

LOADING MEUSE DATA SET

Task 3 : Load the meuse dataset into the workspace.

The data function loads a dataset. We show the contents of the workspace

before and after with the ls \list objects" function:

> ls()

character(0)

> data(meuse)

> ls()

[1] "meuse"

Page 9: Pengenalan R untuk data spasial - IPB University Spatial Statistics/P1- Pengenalan R untuk...INSTALLING R AND RSTUDIO If you do not have R and RStudio on your computer, proceed as

WHAT OBJECTS WERE IN THE WORKSPACE BEFORE

AND AFTER LOADING THE MEUSE DATASET?

Page 10: Pengenalan R untuk data spasial - IPB University Spatial Statistics/P1- Pengenalan R untuk...INSTALLING R AND RSTUDIO If you do not have R and RStudio on your computer, proceed as

TASK 4 : EXAMINE THE STRUCTURE OF THE MEUSE DATASET

The str \structure" function shows the structure of an R object:

Page 11: Pengenalan R untuk data spasial - IPB University Spatial Statistics/P1- Pengenalan R untuk...INSTALLING R AND RSTUDIO If you do not have R and RStudio on your computer, proceed as

DESCRIPTION OF MEUSE DATA SET

Page 12: Pengenalan R untuk data spasial - IPB University Spatial Statistics/P1- Pengenalan R untuk...INSTALLING R AND RSTUDIO If you do not have R and RStudio on your computer, proceed as

INTRODUCTION TO SPATIAL DATA TYPE

Page 13: Pengenalan R untuk data spasial - IPB University Spatial Statistics/P1- Pengenalan R untuk...INSTALLING R AND RSTUDIO If you do not have R and RStudio on your computer, proceed as
Page 14: Pengenalan R untuk data spasial - IPB University Spatial Statistics/P1- Pengenalan R untuk...INSTALLING R AND RSTUDIO If you do not have R and RStudio on your computer, proceed as

PLOT OF MEUSE DATA SET

Page 15: Pengenalan R untuk data spasial - IPB University Spatial Statistics/P1- Pengenalan R untuk...INSTALLING R AND RSTUDIO If you do not have R and RStudio on your computer, proceed as

PLOT THE DATA

> coordinates(meuse) <- c("x", "y")

> plot(meuse)

> title("points")

Page 16: Pengenalan R untuk data spasial - IPB University Spatial Statistics/P1- Pengenalan R untuk...INSTALLING R AND RSTUDIO If you do not have R and RStudio on your computer, proceed as

PLOT THE DATA

Page 17: Pengenalan R untuk data spasial - IPB University Spatial Statistics/P1- Pengenalan R untuk...INSTALLING R AND RSTUDIO If you do not have R and RStudio on your computer, proceed as

PLOT THE DATA

Page 18: Pengenalan R untuk data spasial - IPB University Spatial Statistics/P1- Pengenalan R untuk...INSTALLING R AND RSTUDIO If you do not have R and RStudio on your computer, proceed as

PLOT THE DATA

Page 19: Pengenalan R untuk data spasial - IPB University Spatial Statistics/P1- Pengenalan R untuk...INSTALLING R AND RSTUDIO If you do not have R and RStudio on your computer, proceed as

DATA RASTER

f <- system.file("external/test.grd", package="raster")

f

r <- raster(f)

plot(f)

Page 20: Pengenalan R untuk data spasial - IPB University Spatial Statistics/P1- Pengenalan R untuk...INSTALLING R AND RSTUDIO If you do not have R and RStudio on your computer, proceed as

MENGGUNAKAN DATA EKSTERNAL

Page 21: Pengenalan R untuk data spasial - IPB University Spatial Statistics/P1- Pengenalan R untuk...INSTALLING R AND RSTUDIO If you do not have R and RStudio on your computer, proceed as

DATA PERTUMBUHAN PENDUDUK

Impor data:

datapop<-read.csv('http://bit.ly/Popgrowth2000',

header=T, sep=',')

Page 22: Pengenalan R untuk data spasial - IPB University Spatial Statistics/P1- Pengenalan R untuk...INSTALLING R AND RSTUDIO If you do not have R and RStudio on your computer, proceed as

DATA PERTUMBUHAN PENDUDUK

View(datapop)

Page 23: Pengenalan R untuk data spasial - IPB University Spatial Statistics/P1- Pengenalan R untuk...INSTALLING R AND RSTUDIO If you do not have R and RStudio on your computer, proceed as

PLOT THE DATA POINTS

coordinates(datapop)<-c("Longitude","Latitude")

plot(datapop)

Page 24: Pengenalan R untuk data spasial - IPB University Spatial Statistics/P1- Pengenalan R untuk...INSTALLING R AND RSTUDIO If you do not have R and RStudio on your computer, proceed as

PLOT THE DATA POINTS

size<-datapop$PopGrowth_2000/sum(datapop$PopGrowth_2000)

plot(datapop,pch=20, col="steelblue", cex=size*100)

Page 25: Pengenalan R untuk data spasial - IPB University Spatial Statistics/P1- Pengenalan R untuk...INSTALLING R AND RSTUDIO If you do not have R and RStudio on your computer, proceed as

MENAMBAHKAN PETA DUNIA

install.packages("rworldmap")

library(rworldmap)

data(package="rworldmap")

data(countriesCoarse,envir=environment(),package="rworldmap")

Page 26: Pengenalan R untuk data spasial - IPB University Spatial Statistics/P1- Pengenalan R untuk...INSTALLING R AND RSTUDIO If you do not have R and RStudio on your computer, proceed as

DATA PETA DUNIA

Page 27: Pengenalan R untuk data spasial - IPB University Spatial Statistics/P1- Pengenalan R untuk...INSTALLING R AND RSTUDIO If you do not have R and RStudio on your computer, proceed as

PETA DUNIA

plot(countriesCoarse)

Page 28: Pengenalan R untuk data spasial - IPB University Spatial Statistics/P1- Pengenalan R untuk...INSTALLING R AND RSTUDIO If you do not have R and RStudio on your computer, proceed as

PETA DUNIA + DATA PERTUMBUHAN PENDUDUK

plot(datapop,add=T, pch=20)

Page 29: Pengenalan R untuk data spasial - IPB University Spatial Statistics/P1- Pengenalan R untuk...INSTALLING R AND RSTUDIO If you do not have R and RStudio on your computer, proceed as

PLOT THE DATA

Coba tampilkan data pertumbuhan pendudukdengan ukuran titik sesuaidengan besarnyapertumbuhan, pada petadunia.

Page 30: Pengenalan R untuk data spasial - IPB University Spatial Statistics/P1- Pengenalan R untuk...INSTALLING R AND RSTUDIO If you do not have R and RStudio on your computer, proceed as

RASTERIZE

library(raster)

r <- raster(datapop)

res(r)<-c(5,5)

nc <- rasterize(coordinates(datapop), r, fun=mean, background=NA)

plot(nc)

plot(countriesCoarse, add=TRUE)

Page 31: Pengenalan R untuk data spasial - IPB University Spatial Statistics/P1- Pengenalan R untuk...INSTALLING R AND RSTUDIO If you do not have R and RStudio on your computer, proceed as

CARA LAIN MENAMPILKAN PETA DAN DATA

install.packages("ggmap")

library(ggmap)

map <- get_map(location = 'Indonesia', zoom = 4)

plot(map)

datapop<-read.csv('http://bit.ly/Popgrowth2000', header=T,

sep=',')

ggmap(map)+geom_point(aes(x = Longitude, y = Latitude),

data = pop_ina,col="red")

Page 32: Pengenalan R untuk data spasial - IPB University Spatial Statistics/P1- Pengenalan R untuk...INSTALLING R AND RSTUDIO If you do not have R and RStudio on your computer, proceed as
Page 33: Pengenalan R untuk data spasial - IPB University Spatial Statistics/P1- Pengenalan R untuk...INSTALLING R AND RSTUDIO If you do not have R and RStudio on your computer, proceed as

TUGAS MANDIRI : PETA PULAU JAWA

1. Load package untuk mengimpor data polygon (shape file):

2. Mengimpor data dari direktori (data tersedia di http://bit.ly/ShapeFile_Jawa)

library(rgdal)

menggunakan fungsi readOGR:

readOGR(dsn=‘folder (direktori) tempat shape file disimpan’, layer=‘nama shape file (tanpa .shp extension)’)

Contoh:

jawa<-readOGR(dsn='D:/Belajar/Spasial/R/Map of Jawa (original)',

layer='jawa')

Page 34: Pengenalan R untuk data spasial - IPB University Spatial Statistics/P1- Pengenalan R untuk...INSTALLING R AND RSTUDIO If you do not have R and RStudio on your computer, proceed as

TUGAS MANDIRI : PETA PULAU JAWA

Pratinjau data :

Page 35: Pengenalan R untuk data spasial - IPB University Spatial Statistics/P1- Pengenalan R untuk...INSTALLING R AND RSTUDIO If you do not have R and RStudio on your computer, proceed as

TUGAS MANDIRI : PETA PULAU JAWA

3. Menampilkan peta Pulau Jawa

4. Menampilkan nama kota/kabupaten

plot(jawa)

text(jawa,'NAMA_KAB',cex=0.5)

Page 36: Pengenalan R untuk data spasial - IPB University Spatial Statistics/P1- Pengenalan R untuk...INSTALLING R AND RSTUDIO If you do not have R and RStudio on your computer, proceed as

TUGAS MANDIRI : PETA PULAU JAWA

5. Memberi warna yang berbeda utk setiap Propinsi

plot(jawa,col=jawa$KODE_PROP-30)

Page 37: Pengenalan R untuk data spasial - IPB University Spatial Statistics/P1- Pengenalan R untuk...INSTALLING R AND RSTUDIO If you do not have R and RStudio on your computer, proceed as

TUGAS MANDIRI : PETA PULAU JAWA

Mengganti referensi warna

Page 38: Pengenalan R untuk data spasial - IPB University Spatial Statistics/P1- Pengenalan R untuk...INSTALLING R AND RSTUDIO If you do not have R and RStudio on your computer, proceed as

TUGAS MANDIRI : PETA PULAU JAWA

Mengganti referensi warna

Page 39: Pengenalan R untuk data spasial - IPB University Spatial Statistics/P1- Pengenalan R untuk...INSTALLING R AND RSTUDIO If you do not have R and RStudio on your computer, proceed as

TERIMA KASIH