SlideShare une entreprise Scribd logo
1  sur  37
The good, the bad & the pretty
Spatial data analysis with R
Robert Hijmans
University of California, Davis
May 2013
Spatial is special
• Complex: geometry and attributes
• Earth is flat? Map projections
• Size: lots and lots of it, multivariate, time series
• Special plots: maps
• First Law of Geography: nearby things are similar
– Statistical assumptions: violated
– Interpolation: possible
GIS* –
● Visual interaction –
• Data management –
• Geometric operations –
• Standard workflows –
• Single map production –
• Click, click, click & click –
• Speed of execution –
• Cumbersome –
Don't we have GIS for that?
– R
– Data & model focused ●
– Analysis ●
– Attributes as important ●
– Creativity & innovation ●
– Many (simpler) maps ●
– Repeatability (single script) ●
– Speed of development ●
– Easy & powerful (& free) ●
* there are many different GISs and they evolve
Geometry of spatial objects (‘vector’)
points, lines, polygons
X
Y
(Xmin, Ymax)
dimX
dimY
(Xmax, Ymin)
Geometry of spatial field (grid / raster data)
row 1
row 6
col 1 col 5
1 2 3 4 5
6 7
26 27 28 29 30
24 25
MODIS, 22 May, 2013
Representing spatial data
sp classes:
SpatialPointsDataFrame
SpatialLinesDataFrame
SpatialPolygonsDataFrame
SpatialGridDataFrame
SpatialPixelsDataFrame
rgdal
read/write of object (vector) and raster data,
(shapefiles, geotiff)
> library(rgdal)
> city <- readOGR('d:/data', 'city')
> elev <- readGDAL('d:/data/elevation.tif')
Map projections
coordinate reference system
Class: CRS
proj4string(city) <- CRS('+proj=lonlat +datum=WGS84')
cityutm <- sptransform(city, CRS('+proj=utm +zone=51'))
Types of spatial analysis*
• Query and reasoning
Where is? How much is this here? How to get from A to B?
• „Measurement
Area, Distance, Length, Slope
• „Transformation
Buffering, overlay, interpolation
• „Exploration and description
clusters, trends, spatial dependence, fragmentation
• „Optimization
Site selection, re-districting, traveling salesman
• „Inference
Samples from a population, problem of spatial autocorrelation
• Modeling
Climate change effects, impact of nuclear accident, dispersal
* After Michael Goodchild: http://www.csiss.org/aboutus/presentations/files/goodchild_qmss_oct02.pdf
Spatial statistics
• Point pattern analysis
• Geostatistics (kriging)
• Inference (hypothesis testing)
1. Location of points is of prime interest
2. Points are not a sample
3. Points are within a defined study area
4. Points should be true incidents (not centroids)
Point patterns
Point patterns
> library(spatstat); library(maptools)
> cityOwin <- as(city, “owin”)
> pts <- coordinates(crime)
> p <- ppp(pts[,1], pts[,2], window=cityOwin)
> s <- smooth.ppp(p)
> e <- envelope(p) http://www.spatstat.org/
Geostatistics
> library(gstat)
> data(meuse)
> coordinates(meuse) <- ~x+y
> spplot(meuse, 'zinc')
1. Measurements are of prime interest (not locations)
2. Points are a sample
3. Unbiased estimates for locations that were not sampled
> x <- krige(log(zinc)~1, meuse, meuse.grid, model = m)
> spplot(x["var1.pred"], main="ordinary kriging predictions")
> spplot(x["var1.var"], main = "ordinary kriging variance")
> f <- houseValue ~ age + nBedrooms
> m <- lm(f1, data=hh)
> summary(m)
Call:
lm(formula = f1, data = hh)
Residuals:
Min 1Q Median 3Q Max
-222541 -67489 -6128 60509 217655
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -628578 233217 -2.695 0.00931 **
age 12695 2480 5.119 4.05e-06 ***
nBedrooms 191889 76756 2.500 0.01543 *
Regression with spatial data
Analyse the model residuals for SA (e.g. Moran's I)
> library(spdep)
> cb <- poly2nb(ca)
> lw <- nb2listw(cb)
> plot(ca)
> plot(lw, coordinates(ca),
add=TRUE, col="red")
> moran.test(residuals, lw)
Moran's I test under randomisation
Moran I statistic standard deviate = 2.6926, p-value = 0.003545
alternative hypothesis: greater
sample estimates:
Moran I statistic Expectation Variance
0.158977893 -0.010101010 0.003943149
If SA ‘significant’ then you could
• Re-specify your model
• Permit the coefficients,  , to vary spatially
(GWR)
• Modify the regression model to incorporate the SA
• Proceed and ignore SA?
OLS: Y = Xβ + e
Autogregressive model: Y = ρWY + e
Simultaneous Autoregressive Models:
SAR-lag: Y = ρWY + Xβ + e
(endogenous, inherent spat. autocorrelation, diffusion )
SAR-err: Y = Xβ + λWu + e
(exogenous, induced spatial autocorrelation)
SAR-mix: Y = ρWY + Xβ + WXγ + e
CAR
raster package
• new classes (‘S4’) for raster data
• no file size restrictions
• file formats: gdal, ncdf, ‘native’
• > 200 functions
RasterLayer
> library(raster)
>
> x <- raster(ncol=10, nrow=5)
>
> x <- raster('volcano.tif')
>
> x
class : RasterLayer
dimensions : 87, 61, 5307 (nrow, ncol, ncell)
resolution : 10, 10 (x, y)
extent : 2667400, 2668010, 6478700, 6479570 (xmin, xmax, …
coord. ref. : +proj=nzmg +lat_0=-41 +lon_0=173 +x_0=251
values : d:datavolcano.tif
min value : 94
max value : 195
> str(x)
Formal class 'RasterLayer' [package "raster"] with 16 slots
..@ file :Formal class '.RasterFile' [package "raster"] with 9 slots
. . .. ..@ name : chr “d:datavolcano.tif“
.. .. ..@ driver : chr "gdal"
..@ data :Formal class '.SingleLayerData' [package "raster"] with 11 slots
.. .. ..@ values : logi(0)
.. .. ..@ inmemory : logi FALSE
.. .. ..@ min : num 94
. . .. ..@ max : num 195
..@ extent :Formal class 'Extent' [package "raster"] with 4 slots
.. .. ..@ xmin: num 2667400
.. .. ..@ xmax: num 2668010
.. @ rotation :Formal class '.Rotation' [package "raster"] with 2 slots
.. .. ..@ geotrans: num(0)
.. .. ..@ transfun:function ()
..@ ncols : int 61
..@ nrows : int 87
..@ crs :Formal class 'CRS' [package "sp"] with 1 slots
.. .. ..@ projargs: chr " +proj=nzmg +lat_0=-41 +lon_0=173 +x_0=2510000 +y_0=6023150
..@ layernames: chr "volcano”
RasterLayer
Multiple layers
RasterStack - many files
RasterBrick - single files
> s <- stack(x, x*2, sqrt(x))
>
> s
class : RasterStack
dimensions : 87, 61, 5307, 3 (nrow, ncol, ncell,
nlayers)
resolution : 0.01639344, 0.01149425 (x, y)
extent : 0, 1, 0, 1 (xmin, xmax, ymin, ymax)
coord. ref. : NA
min values : 94.0, 188.0, 9.7
max values : 195, 390, 14
layer names : layer.1, layer.2, layer.3
0
1 – 10
11 – 25
26 – 50
51 – 100
> 100
Daily rainfall
Some functions
ncell(x)
xyFromCell(x, 10)
getValues(x, row)
adjacent(x, 10)
writeRaster(x, filename, …)
merge, crop, project, aggregate,
reclass, resample,
rasterize, distance, focal …
“High level”
“Low level”
r <- raster(nc=10, nr=10)
values(r) <- 1:ncell(r)
q <- sqrt(r)
x <- (q + r) * 2
s <- stack(r, q, x)
ss <- s * r
Raster algebra
> elev <- getData('worldclim', var='alt', res=2.5)
> usa1 <- getData('GADM', country='USA', level=1)
> ca <- usa1[usa1$NAME_1 == 'California', ]
> bio <- getData('worldclim', var='bio', res=5)
> library(dismo)
> bg <- sampleRandom(bio, ext=extent(ca), size=1000)
> obs <- extract(bio, bigfoot)
> alt <- crop(elev, ca)
> alt <- mask(alt, ca)
> plot(alt)
> points(bigfoot)
Modeling bigfoot
(after Hickerson et al., 2008)
data from:
http://www.bfro.net/news/google_earth.asp
Likelihood
of occurrence
> d <- data.frame(pa=c(rep(1, nrow(obs)), rep(0, nrow(bg))),
rbind(obs, bg))
> library(randomForest)
> rf <- randomForest(pa~., data=d)
> pred <- predict(bio, rf)
> plot(pred)
> plot(ca, add=T)
> points(sel2, col='blue', pch=20)
Visualization
plot
plotRGB
contour
plot3D
…
> library(rasterVis)
> plot(s, addfun=function()plot(esp, add=T))
> library(rasterVis)
> alt <- getData('worldclim', var='alt', res=2.5)
> usa1 <- getData('GADM', country='USA', level=1)
> ca <- usa1[usa1$NAME_1 == 'California', ]
> alt <- crop(alt, extent(ca)+ 0.5)
> alt <- mask(alt, ca)
> levelplot(alt, par.settings=GrTheme)
http://www.revolutionanalytics.com/news-events/free-webinars/2012/ggplot2-with-hadley-wickham/
http://spatialanalysis.co.uk/2012/02/great-maps-ggplot2/
> library(dismo)
> g <- gmap('Mountain View, CA')
> plot(g, interpolate=T)
> xy <- geocode("2600 Casey Ave, Mountain View, CA")
> points(Mercator(xy[,2:3]), col='red', pch='*', cex=5)
http://flowingdata.com/2011/05/11/how-to-map-connections-with-great-circles/
> library(geosphere)
> inter <- gcIntermediate(lonlat1, lonlat2, n=100)
> lines(inter, col=colors, lwd=lwd)
.
http://cran.r-project.org/web/views/Spatial.html
More info

Contenu connexe

Tendances

Surface Representations using GIS AND Topographical Mapping
Surface Representations using GIS AND Topographical MappingSurface Representations using GIS AND Topographical Mapping
Surface Representations using GIS AND Topographical MappingNAXA-Developers
 
Commercial Sector Applications of GIS
Commercial Sector Applications of GISCommercial Sector Applications of GIS
Commercial Sector Applications of GISKM Chicago
 
Janine Illian R-INLA
Janine Illian R-INLAJanine Illian R-INLA
Janine Illian R-INLADavid LeBauer
 
Comparison of image fusion methods
Comparison of image fusion methodsComparison of image fusion methods
Comparison of image fusion methodsAmr Nasr
 
TYBSC IT PGIS Unit III Chapter I Spatial Referencing and Positioning
TYBSC IT PGIS Unit III Chapter I Spatial Referencing and PositioningTYBSC IT PGIS Unit III Chapter I Spatial Referencing and Positioning
TYBSC IT PGIS Unit III Chapter I Spatial Referencing and PositioningArti Parab Academics
 
Health GIS (Geographic Information System)
Health GIS (Geographic Information System)Health GIS (Geographic Information System)
Health GIS (Geographic Information System)Zulfiquer Ahmed Amin
 
Introduction to GIS
Introduction to GISIntroduction to GIS
Introduction to GISEhsan Hamzei
 
gis project planning and management
gis project planning and managementgis project planning and management
gis project planning and managementAbhiram Kanigolla
 
Geographic information system
Geographic information systemGeographic information system
Geographic information systemOssamaElShanawany
 
R programming language in spatial analysis
R programming language in spatial analysisR programming language in spatial analysis
R programming language in spatial analysisAbhiram Kanigolla
 
Spatial Autocorrelation
Spatial AutocorrelationSpatial Autocorrelation
Spatial AutocorrelationEhsan Hamzei
 

Tendances (20)

Surface Representations using GIS AND Topographical Mapping
Surface Representations using GIS AND Topographical MappingSurface Representations using GIS AND Topographical Mapping
Surface Representations using GIS AND Topographical Mapping
 
Commercial Sector Applications of GIS
Commercial Sector Applications of GISCommercial Sector Applications of GIS
Commercial Sector Applications of GIS
 
Gis
GisGis
Gis
 
Janine Illian R-INLA
Janine Illian R-INLAJanine Illian R-INLA
Janine Illian R-INLA
 
Gnss data-processing
Gnss data-processingGnss data-processing
Gnss data-processing
 
Comparison of image fusion methods
Comparison of image fusion methodsComparison of image fusion methods
Comparison of image fusion methods
 
TYBSC IT PGIS Unit III Chapter I Spatial Referencing and Positioning
TYBSC IT PGIS Unit III Chapter I Spatial Referencing and PositioningTYBSC IT PGIS Unit III Chapter I Spatial Referencing and Positioning
TYBSC IT PGIS Unit III Chapter I Spatial Referencing and Positioning
 
Health GIS (Geographic Information System)
Health GIS (Geographic Information System)Health GIS (Geographic Information System)
Health GIS (Geographic Information System)
 
Introduction to GIS
Introduction to GISIntroduction to GIS
Introduction to GIS
 
Gis
GisGis
Gis
 
gis project planning and management
gis project planning and managementgis project planning and management
gis project planning and management
 
Raster processing
Raster processingRaster processing
Raster processing
 
Geographic information system
Geographic information systemGeographic information system
Geographic information system
 
introduction to GIS
introduction to GIS introduction to GIS
introduction to GIS
 
Urban planing & gis
Urban planing & gisUrban planing & gis
Urban planing & gis
 
R programming language in spatial analysis
R programming language in spatial analysisR programming language in spatial analysis
R programming language in spatial analysis
 
Geo-spatial Analysis and Modelling
Geo-spatial Analysis and ModellingGeo-spatial Analysis and Modelling
Geo-spatial Analysis and Modelling
 
( G . i . s )
( G . i . s )( G . i . s )
( G . i . s )
 
Spatial Autocorrelation
Spatial AutocorrelationSpatial Autocorrelation
Spatial Autocorrelation
 
My ppt on gis
My ppt on gisMy ppt on gis
My ppt on gis
 

En vedette

R Spatial Analysis using SP
R Spatial Analysis using SPR Spatial Analysis using SP
R Spatial Analysis using SPtjagger
 
Using R to Visualize Spatial Data: R as GIS - Guy Lansley
Using R to Visualize Spatial Data: R as GIS - Guy LansleyUsing R to Visualize Spatial Data: R as GIS - Guy Lansley
Using R to Visualize Spatial Data: R as GIS - Guy LansleyGuy Lansley
 
Esriuk_track3_esri spatial analysis presentation
Esriuk_track3_esri spatial analysis presentationEsriuk_track3_esri spatial analysis presentation
Esriuk_track3_esri spatial analysis presentationEsri UK
 
Spatial Analysis and Geomatics
Spatial Analysis and GeomaticsSpatial Analysis and Geomatics
Spatial Analysis and GeomaticsRich Heimann
 
QGIS & Inkscape: Carographic Tools for Attractive Maps
QGIS & Inkscape: Carographic Tools for Attractive MapsQGIS & Inkscape: Carographic Tools for Attractive Maps
QGIS & Inkscape: Carographic Tools for Attractive MapsMichele Tobias
 
Spatial Data Science with R
Spatial Data Science with RSpatial Data Science with R
Spatial Data Science with Ramsantac
 
Intro to plyr for Davis R Users' Group, by Steve Culman
Intro to plyr for Davis R Users' Group, by Steve CulmanIntro to plyr for Davis R Users' Group, by Steve Culman
Intro to plyr for Davis R Users' Group, by Steve CulmanNoam Ross
 
Modeling Count-based Raster Data with ArcGIS and R
Modeling Count-based Raster Data with ArcGIS and RModeling Count-based Raster Data with ArcGIS and R
Modeling Count-based Raster Data with ArcGIS and RAzavea
 
Using R for Climate Raster Data Extraction
Using R for Climate Raster Data ExtractionUsing R for Climate Raster Data Extraction
Using R for Climate Raster Data ExtractionMichele Tobias
 
New analytical methods for geocomputation - Guy Lansley, UCL
New analytical methods for geocomputation - Guy Lansley, UCLNew analytical methods for geocomputation - Guy Lansley, UCL
New analytical methods for geocomputation - Guy Lansley, UCLGuy Lansley
 
Linking Socio-economic and Demographic Characteristics to Twitter Topics - Gu...
Linking Socio-economic and Demographic Characteristics to Twitter Topics - Gu...Linking Socio-economic and Demographic Characteristics to Twitter Topics - Gu...
Linking Socio-economic and Demographic Characteristics to Twitter Topics - Gu...Guy Lansley
 
General Additive Models in R
General Additive Models in RGeneral Additive Models in R
General Additive Models in RNoam Ross
 
An introduction to structural equation models in R using the Lavaan package
An introduction to structural equation models in R using the Lavaan packageAn introduction to structural equation models in R using the Lavaan package
An introduction to structural equation models in R using the Lavaan packageNoam Ross
 
Finding Meaning in Points, Areas and Surfaces: Spatial Analysis in R
Finding Meaning in Points, Areas and Surfaces: Spatial Analysis in RFinding Meaning in Points, Areas and Surfaces: Spatial Analysis in R
Finding Meaning in Points, Areas and Surfaces: Spatial Analysis in RRevolution Analytics
 
Spatial analysis and modeling
Spatial analysis and modelingSpatial analysis and modeling
Spatial analysis and modelingTolasa_F
 

En vedette (18)

Geospatial Data in R
Geospatial Data in RGeospatial Data in R
Geospatial Data in R
 
R Spatial Analysis using SP
R Spatial Analysis using SPR Spatial Analysis using SP
R Spatial Analysis using SP
 
Maps with leafletR
Maps with leafletRMaps with leafletR
Maps with leafletR
 
Using R to Visualize Spatial Data: R as GIS - Guy Lansley
Using R to Visualize Spatial Data: R as GIS - Guy LansleyUsing R to Visualize Spatial Data: R as GIS - Guy Lansley
Using R to Visualize Spatial Data: R as GIS - Guy Lansley
 
Esriuk_track3_esri spatial analysis presentation
Esriuk_track3_esri spatial analysis presentationEsriuk_track3_esri spatial analysis presentation
Esriuk_track3_esri spatial analysis presentation
 
Spatial Analysis and Geomatics
Spatial Analysis and GeomaticsSpatial Analysis and Geomatics
Spatial Analysis and Geomatics
 
QGIS & Inkscape: Carographic Tools for Attractive Maps
QGIS & Inkscape: Carographic Tools for Attractive MapsQGIS & Inkscape: Carographic Tools for Attractive Maps
QGIS & Inkscape: Carographic Tools for Attractive Maps
 
Spatial Data Science with R
Spatial Data Science with RSpatial Data Science with R
Spatial Data Science with R
 
Intro to plyr for Davis R Users' Group, by Steve Culman
Intro to plyr for Davis R Users' Group, by Steve CulmanIntro to plyr for Davis R Users' Group, by Steve Culman
Intro to plyr for Davis R Users' Group, by Steve Culman
 
Modeling Count-based Raster Data with ArcGIS and R
Modeling Count-based Raster Data with ArcGIS and RModeling Count-based Raster Data with ArcGIS and R
Modeling Count-based Raster Data with ArcGIS and R
 
Using R for Climate Raster Data Extraction
Using R for Climate Raster Data ExtractionUsing R for Climate Raster Data Extraction
Using R for Climate Raster Data Extraction
 
Inkscape cartography
Inkscape cartographyInkscape cartography
Inkscape cartography
 
New analytical methods for geocomputation - Guy Lansley, UCL
New analytical methods for geocomputation - Guy Lansley, UCLNew analytical methods for geocomputation - Guy Lansley, UCL
New analytical methods for geocomputation - Guy Lansley, UCL
 
Linking Socio-economic and Demographic Characteristics to Twitter Topics - Gu...
Linking Socio-economic and Demographic Characteristics to Twitter Topics - Gu...Linking Socio-economic and Demographic Characteristics to Twitter Topics - Gu...
Linking Socio-economic and Demographic Characteristics to Twitter Topics - Gu...
 
General Additive Models in R
General Additive Models in RGeneral Additive Models in R
General Additive Models in R
 
An introduction to structural equation models in R using the Lavaan package
An introduction to structural equation models in R using the Lavaan packageAn introduction to structural equation models in R using the Lavaan package
An introduction to structural equation models in R using the Lavaan package
 
Finding Meaning in Points, Areas and Surfaces: Spatial Analysis in R
Finding Meaning in Points, Areas and Surfaces: Spatial Analysis in RFinding Meaning in Points, Areas and Surfaces: Spatial Analysis in R
Finding Meaning in Points, Areas and Surfaces: Spatial Analysis in R
 
Spatial analysis and modeling
Spatial analysis and modelingSpatial analysis and modeling
Spatial analysis and modeling
 

Similaire à Spatial Analysis with R - the Good, the Bad, and the Pretty

Practical data science_public
Practical data science_publicPractical data science_public
Practical data science_publicLong Nguyen
 
Introduction to R.pptx
Introduction to R.pptxIntroduction to R.pptx
Introduction to R.pptxkarthikks82
 
Exploratory Analysis Part1 Coursera DataScience Specialisation
Exploratory Analysis Part1 Coursera DataScience SpecialisationExploratory Analysis Part1 Coursera DataScience Specialisation
Exploratory Analysis Part1 Coursera DataScience SpecialisationWesley Goi
 
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov VyacheslavSeminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov VyacheslavVyacheslav Arbuzov
 
Introduction to R for data science
Introduction to R for data scienceIntroduction to R for data science
Introduction to R for data scienceLong Nguyen
 
Feature Engineering - Getting most out of data for predictive models - TDC 2017
Feature Engineering - Getting most out of data for predictive models - TDC 2017Feature Engineering - Getting most out of data for predictive models - TDC 2017
Feature Engineering - Getting most out of data for predictive models - TDC 2017Gabriel Moreira
 
Opensource gis development - part 4
Opensource gis development - part 4Opensource gis development - part 4
Opensource gis development - part 4Andrea Antonello
 
Data analysis with R
Data analysis with RData analysis with R
Data analysis with RShareThis
 
Functional Programming, simplified
Functional Programming, simplifiedFunctional Programming, simplified
Functional Programming, simplifiedNaveenkumar Muguda
 
GIS_Whirlwind_Tour.ppt
GIS_Whirlwind_Tour.pptGIS_Whirlwind_Tour.ppt
GIS_Whirlwind_Tour.pptFatima891926
 
GIS_Whirlwind_Tour.ppt
GIS_Whirlwind_Tour.pptGIS_Whirlwind_Tour.ppt
GIS_Whirlwind_Tour.pptsafayetmim1
 
GIS_Whirlwind_Tour.ppt
GIS_Whirlwind_Tour.pptGIS_Whirlwind_Tour.ppt
GIS_Whirlwind_Tour.pptvikramvsu
 
2024.03.22 - Mike Heddes - Introduction to Hyperdimensional Computing.pdf
2024.03.22 - Mike Heddes - Introduction to Hyperdimensional Computing.pdf2024.03.22 - Mike Heddes - Introduction to Hyperdimensional Computing.pdf
2024.03.22 - Mike Heddes - Introduction to Hyperdimensional Computing.pdfAdvanced-Concepts-Team
 

Similaire à Spatial Analysis with R - the Good, the Bad, and the Pretty (20)

Practical data science_public
Practical data science_publicPractical data science_public
Practical data science_public
 
Introduction to R.pptx
Introduction to R.pptxIntroduction to R.pptx
Introduction to R.pptx
 
Data preprocessing
Data preprocessingData preprocessing
Data preprocessing
 
Exploratory Analysis Part1 Coursera DataScience Specialisation
Exploratory Analysis Part1 Coursera DataScience SpecialisationExploratory Analysis Part1 Coursera DataScience Specialisation
Exploratory Analysis Part1 Coursera DataScience Specialisation
 
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov VyacheslavSeminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
 
Big datacourse
Big datacourseBig datacourse
Big datacourse
 
Introduction to R for data science
Introduction to R for data scienceIntroduction to R for data science
Introduction to R for data science
 
Feature Engineering - Getting most out of data for predictive models - TDC 2017
Feature Engineering - Getting most out of data for predictive models - TDC 2017Feature Engineering - Getting most out of data for predictive models - TDC 2017
Feature Engineering - Getting most out of data for predictive models - TDC 2017
 
Generalized Reinforcement Learning
Generalized Reinforcement LearningGeneralized Reinforcement Learning
Generalized Reinforcement Learning
 
Tractor Pulling on Data Warehouse
Tractor Pulling on Data WarehouseTractor Pulling on Data Warehouse
Tractor Pulling on Data Warehouse
 
R programmingmilano
R programmingmilanoR programmingmilano
R programmingmilano
 
Opensource gis development - part 4
Opensource gis development - part 4Opensource gis development - part 4
Opensource gis development - part 4
 
NumPy/SciPy Statistics
NumPy/SciPy StatisticsNumPy/SciPy Statistics
NumPy/SciPy Statistics
 
Data analysis with R
Data analysis with RData analysis with R
Data analysis with R
 
Functional Programming, simplified
Functional Programming, simplifiedFunctional Programming, simplified
Functional Programming, simplified
 
GIS_Whirlwind_Tour.ppt
GIS_Whirlwind_Tour.pptGIS_Whirlwind_Tour.ppt
GIS_Whirlwind_Tour.ppt
 
GIS_Whirlwind_Tour.ppt
GIS_Whirlwind_Tour.pptGIS_Whirlwind_Tour.ppt
GIS_Whirlwind_Tour.ppt
 
GIS_Whirlwind_Tour.ppt
GIS_Whirlwind_Tour.pptGIS_Whirlwind_Tour.ppt
GIS_Whirlwind_Tour.ppt
 
GIS_Whirlwind_Tour.ppt
GIS_Whirlwind_Tour.pptGIS_Whirlwind_Tour.ppt
GIS_Whirlwind_Tour.ppt
 
2024.03.22 - Mike Heddes - Introduction to Hyperdimensional Computing.pdf
2024.03.22 - Mike Heddes - Introduction to Hyperdimensional Computing.pdf2024.03.22 - Mike Heddes - Introduction to Hyperdimensional Computing.pdf
2024.03.22 - Mike Heddes - Introduction to Hyperdimensional Computing.pdf
 

Plus de Noam Ross

R and the forest vegetation simulator
R and the forest vegetation simulatorR and the forest vegetation simulator
R and the forest vegetation simulatorNoam Ross
 
Andersen et al. 2004: Stoichiometry and Dynamics
Andersen et al. 2004: Stoichiometry and DynamicsAndersen et al. 2004: Stoichiometry and Dynamics
Andersen et al. 2004: Stoichiometry and DynamicsNoam Ross
 
Agren 2012 - by Brian Smithers
Agren 2012 - by Brian SmithersAgren 2012 - by Brian Smithers
Agren 2012 - by Brian SmithersNoam Ross
 
Stoichiometry of the Microbial Loop: J. Matthew Haggerty
Stoichiometry of the Microbial Loop: J. Matthew HaggertyStoichiometry of the Microbial Loop: J. Matthew Haggerty
Stoichiometry of the Microbial Loop: J. Matthew HaggertyNoam Ross
 
Ecological Stoichiometry: The Consumer Connection: Matt Whalen
Ecological Stoichiometry: The Consumer Connection: Matt WhalenEcological Stoichiometry: The Consumer Connection: Matt Whalen
Ecological Stoichiometry: The Consumer Connection: Matt WhalenNoam Ross
 
Stoichiometry of the Microbial Loop: J. Matthew Haggerty
Stoichiometry of the Microbial Loop: J. Matthew HaggertyStoichiometry of the Microbial Loop: J. Matthew Haggerty
Stoichiometry of the Microbial Loop: J. Matthew HaggertyNoam Ross
 
Marklein CNP stoichiometry
Marklein CNP stoichiometryMarklein CNP stoichiometry
Marklein CNP stoichiometryNoam Ross
 
Modifying River-Floodplain Systems: A Historical and Ecological Perspective
Modifying River-Floodplain Systems: A Historical and Ecological PerspectiveModifying River-Floodplain Systems: A Historical and Ecological Perspective
Modifying River-Floodplain Systems: A Historical and Ecological PerspectiveNoam Ross
 
Emerging Forest Disease
Emerging Forest DiseaseEmerging Forest Disease
Emerging Forest DiseaseNoam Ross
 
Baskett Lab Uncertainty lab meeting
Baskett Lab Uncertainty lab meetingBaskett Lab Uncertainty lab meeting
Baskett Lab Uncertainty lab meetingNoam Ross
 

Plus de Noam Ross (10)

R and the forest vegetation simulator
R and the forest vegetation simulatorR and the forest vegetation simulator
R and the forest vegetation simulator
 
Andersen et al. 2004: Stoichiometry and Dynamics
Andersen et al. 2004: Stoichiometry and DynamicsAndersen et al. 2004: Stoichiometry and Dynamics
Andersen et al. 2004: Stoichiometry and Dynamics
 
Agren 2012 - by Brian Smithers
Agren 2012 - by Brian SmithersAgren 2012 - by Brian Smithers
Agren 2012 - by Brian Smithers
 
Stoichiometry of the Microbial Loop: J. Matthew Haggerty
Stoichiometry of the Microbial Loop: J. Matthew HaggertyStoichiometry of the Microbial Loop: J. Matthew Haggerty
Stoichiometry of the Microbial Loop: J. Matthew Haggerty
 
Ecological Stoichiometry: The Consumer Connection: Matt Whalen
Ecological Stoichiometry: The Consumer Connection: Matt WhalenEcological Stoichiometry: The Consumer Connection: Matt Whalen
Ecological Stoichiometry: The Consumer Connection: Matt Whalen
 
Stoichiometry of the Microbial Loop: J. Matthew Haggerty
Stoichiometry of the Microbial Loop: J. Matthew HaggertyStoichiometry of the Microbial Loop: J. Matthew Haggerty
Stoichiometry of the Microbial Loop: J. Matthew Haggerty
 
Marklein CNP stoichiometry
Marklein CNP stoichiometryMarklein CNP stoichiometry
Marklein CNP stoichiometry
 
Modifying River-Floodplain Systems: A Historical and Ecological Perspective
Modifying River-Floodplain Systems: A Historical and Ecological PerspectiveModifying River-Floodplain Systems: A Historical and Ecological Perspective
Modifying River-Floodplain Systems: A Historical and Ecological Perspective
 
Emerging Forest Disease
Emerging Forest DiseaseEmerging Forest Disease
Emerging Forest Disease
 
Baskett Lab Uncertainty lab meeting
Baskett Lab Uncertainty lab meetingBaskett Lab Uncertainty lab meeting
Baskett Lab Uncertainty lab meeting
 

Dernier

Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 

Dernier (20)

Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 

Spatial Analysis with R - the Good, the Bad, and the Pretty

  • 1. The good, the bad & the pretty Spatial data analysis with R Robert Hijmans University of California, Davis May 2013
  • 2. Spatial is special • Complex: geometry and attributes • Earth is flat? Map projections • Size: lots and lots of it, multivariate, time series • Special plots: maps • First Law of Geography: nearby things are similar – Statistical assumptions: violated – Interpolation: possible
  • 3. GIS* – ● Visual interaction – • Data management – • Geometric operations – • Standard workflows – • Single map production – • Click, click, click & click – • Speed of execution – • Cumbersome – Don't we have GIS for that? – R – Data & model focused ● – Analysis ● – Attributes as important ● – Creativity & innovation ● – Many (simpler) maps ● – Repeatability (single script) ● – Speed of development ● – Easy & powerful (& free) ● * there are many different GISs and they evolve
  • 4. Geometry of spatial objects (‘vector’) points, lines, polygons X Y
  • 5.
  • 6. (Xmin, Ymax) dimX dimY (Xmax, Ymin) Geometry of spatial field (grid / raster data) row 1 row 6 col 1 col 5 1 2 3 4 5 6 7 26 27 28 29 30 24 25
  • 8. Representing spatial data sp classes: SpatialPointsDataFrame SpatialLinesDataFrame SpatialPolygonsDataFrame SpatialGridDataFrame SpatialPixelsDataFrame rgdal read/write of object (vector) and raster data, (shapefiles, geotiff) > library(rgdal) > city <- readOGR('d:/data', 'city') > elev <- readGDAL('d:/data/elevation.tif')
  • 9. Map projections coordinate reference system Class: CRS proj4string(city) <- CRS('+proj=lonlat +datum=WGS84') cityutm <- sptransform(city, CRS('+proj=utm +zone=51'))
  • 10. Types of spatial analysis* • Query and reasoning Where is? How much is this here? How to get from A to B? • „Measurement Area, Distance, Length, Slope • „Transformation Buffering, overlay, interpolation • „Exploration and description clusters, trends, spatial dependence, fragmentation • „Optimization Site selection, re-districting, traveling salesman • „Inference Samples from a population, problem of spatial autocorrelation • Modeling Climate change effects, impact of nuclear accident, dispersal * After Michael Goodchild: http://www.csiss.org/aboutus/presentations/files/goodchild_qmss_oct02.pdf
  • 11. Spatial statistics • Point pattern analysis • Geostatistics (kriging) • Inference (hypothesis testing)
  • 12. 1. Location of points is of prime interest 2. Points are not a sample 3. Points are within a defined study area 4. Points should be true incidents (not centroids) Point patterns
  • 13. Point patterns > library(spatstat); library(maptools) > cityOwin <- as(city, “owin”) > pts <- coordinates(crime) > p <- ppp(pts[,1], pts[,2], window=cityOwin) > s <- smooth.ppp(p) > e <- envelope(p) http://www.spatstat.org/
  • 14.
  • 15. Geostatistics > library(gstat) > data(meuse) > coordinates(meuse) <- ~x+y > spplot(meuse, 'zinc') 1. Measurements are of prime interest (not locations) 2. Points are a sample 3. Unbiased estimates for locations that were not sampled
  • 16. > x <- krige(log(zinc)~1, meuse, meuse.grid, model = m) > spplot(x["var1.pred"], main="ordinary kriging predictions") > spplot(x["var1.var"], main = "ordinary kriging variance")
  • 17. > f <- houseValue ~ age + nBedrooms > m <- lm(f1, data=hh) > summary(m) Call: lm(formula = f1, data = hh) Residuals: Min 1Q Median 3Q Max -222541 -67489 -6128 60509 217655 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -628578 233217 -2.695 0.00931 ** age 12695 2480 5.119 4.05e-06 *** nBedrooms 191889 76756 2.500 0.01543 * Regression with spatial data
  • 18. Analyse the model residuals for SA (e.g. Moran's I)
  • 19. > library(spdep) > cb <- poly2nb(ca) > lw <- nb2listw(cb) > plot(ca) > plot(lw, coordinates(ca), add=TRUE, col="red") > moran.test(residuals, lw) Moran's I test under randomisation Moran I statistic standard deviate = 2.6926, p-value = 0.003545 alternative hypothesis: greater sample estimates: Moran I statistic Expectation Variance 0.158977893 -0.010101010 0.003943149
  • 20. If SA ‘significant’ then you could • Re-specify your model • Permit the coefficients,  , to vary spatially (GWR) • Modify the regression model to incorporate the SA • Proceed and ignore SA?
  • 21. OLS: Y = Xβ + e Autogregressive model: Y = ρWY + e Simultaneous Autoregressive Models: SAR-lag: Y = ρWY + Xβ + e (endogenous, inherent spat. autocorrelation, diffusion ) SAR-err: Y = Xβ + λWu + e (exogenous, induced spatial autocorrelation) SAR-mix: Y = ρWY + Xβ + WXγ + e CAR
  • 22. raster package • new classes (‘S4’) for raster data • no file size restrictions • file formats: gdal, ncdf, ‘native’ • > 200 functions
  • 23. RasterLayer > library(raster) > > x <- raster(ncol=10, nrow=5) > > x <- raster('volcano.tif') > > x class : RasterLayer dimensions : 87, 61, 5307 (nrow, ncol, ncell) resolution : 10, 10 (x, y) extent : 2667400, 2668010, 6478700, 6479570 (xmin, xmax, … coord. ref. : +proj=nzmg +lat_0=-41 +lon_0=173 +x_0=251 values : d:datavolcano.tif min value : 94 max value : 195
  • 24. > str(x) Formal class 'RasterLayer' [package "raster"] with 16 slots ..@ file :Formal class '.RasterFile' [package "raster"] with 9 slots . . .. ..@ name : chr “d:datavolcano.tif“ .. .. ..@ driver : chr "gdal" ..@ data :Formal class '.SingleLayerData' [package "raster"] with 11 slots .. .. ..@ values : logi(0) .. .. ..@ inmemory : logi FALSE .. .. ..@ min : num 94 . . .. ..@ max : num 195 ..@ extent :Formal class 'Extent' [package "raster"] with 4 slots .. .. ..@ xmin: num 2667400 .. .. ..@ xmax: num 2668010 .. @ rotation :Formal class '.Rotation' [package "raster"] with 2 slots .. .. ..@ geotrans: num(0) .. .. ..@ transfun:function () ..@ ncols : int 61 ..@ nrows : int 87 ..@ crs :Formal class 'CRS' [package "sp"] with 1 slots .. .. ..@ projargs: chr " +proj=nzmg +lat_0=-41 +lon_0=173 +x_0=2510000 +y_0=6023150 ..@ layernames: chr "volcano” RasterLayer
  • 25. Multiple layers RasterStack - many files RasterBrick - single files > s <- stack(x, x*2, sqrt(x)) > > s class : RasterStack dimensions : 87, 61, 5307, 3 (nrow, ncol, ncell, nlayers) resolution : 0.01639344, 0.01149425 (x, y) extent : 0, 1, 0, 1 (xmin, xmax, ymin, ymax) coord. ref. : NA min values : 94.0, 188.0, 9.7 max values : 195, 390, 14 layer names : layer.1, layer.2, layer.3
  • 26. 0 1 – 10 11 – 25 26 – 50 51 – 100 > 100 Daily rainfall
  • 27. Some functions ncell(x) xyFromCell(x, 10) getValues(x, row) adjacent(x, 10) writeRaster(x, filename, …) merge, crop, project, aggregate, reclass, resample, rasterize, distance, focal … “High level” “Low level”
  • 28. r <- raster(nc=10, nr=10) values(r) <- 1:ncell(r) q <- sqrt(r) x <- (q + r) * 2 s <- stack(r, q, x) ss <- s * r Raster algebra
  • 29. > elev <- getData('worldclim', var='alt', res=2.5) > usa1 <- getData('GADM', country='USA', level=1) > ca <- usa1[usa1$NAME_1 == 'California', ] > bio <- getData('worldclim', var='bio', res=5) > library(dismo) > bg <- sampleRandom(bio, ext=extent(ca), size=1000) > obs <- extract(bio, bigfoot) > alt <- crop(elev, ca) > alt <- mask(alt, ca) > plot(alt) > points(bigfoot) Modeling bigfoot (after Hickerson et al., 2008) data from: http://www.bfro.net/news/google_earth.asp
  • 30. Likelihood of occurrence > d <- data.frame(pa=c(rep(1, nrow(obs)), rep(0, nrow(bg))), rbind(obs, bg)) > library(randomForest) > rf <- randomForest(pa~., data=d) > pred <- predict(bio, rf) > plot(pred) > plot(ca, add=T) > points(sel2, col='blue', pch=20)
  • 32. > library(rasterVis) > plot(s, addfun=function()plot(esp, add=T))
  • 33. > library(rasterVis) > alt <- getData('worldclim', var='alt', res=2.5) > usa1 <- getData('GADM', country='USA', level=1) > ca <- usa1[usa1$NAME_1 == 'California', ] > alt <- crop(alt, extent(ca)+ 0.5) > alt <- mask(alt, ca) > levelplot(alt, par.settings=GrTheme)
  • 35. > library(dismo) > g <- gmap('Mountain View, CA') > plot(g, interpolate=T) > xy <- geocode("2600 Casey Ave, Mountain View, CA") > points(Mercator(xy[,2:3]), col='red', pch='*', cex=5)
  • 36. http://flowingdata.com/2011/05/11/how-to-map-connections-with-great-circles/ > library(geosphere) > inter <- gcIntermediate(lonlat1, lonlat2, n=100) > lines(inter, col=colors, lwd=lwd)