diff --git a/.gitignore b/.gitignore index 807ea25..f860853 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,15 @@ .Rproj.user .Rhistory .RData +ESP2_msk_alt.grd +ESP2_msk_alt.gri +ESP2_msk_alt.vrt +ESP_msk_alt.grd +ESP_msk_alt.gri +ESP_msk_alt.vrt +occs.dbf +occs.prj +occs.shp +occs.shx +wc10 +GISwithR-figure diff --git a/GISwithR.Rmd b/GISwithR.Rmd new file mode 100644 index 0000000..e975ab6 --- /dev/null +++ b/GISwithR.Rmd @@ -0,0 +1,234 @@ +GIS with R: slides for the unconverted +======================================================== +author: Francisco Rodriguez-Sanchez +date: @frod_san +2015-11-14 + + +R: not only for stats +===================== + +![](images/R.jpg) + + +R can make beautiful maps +========================= +type: section + + + +Made in R +========== + +![](images/bike_ggplot.png) + +http://spatial.ly/2012/02/great-maps-ggplot2/ + + +Made in R +========= + +![](images/facebook_map.png) + +http://paulbutler.org/archives/visualizing-facebook-friends/ + + +Made in R +========= + +![](images/airMadrid_stamen.png) + +http://oscarperpinan.github.io/spacetime-vis/ + + +Made in R +========= + +![](images/cft.png) + +http://oscarperpinan.github.io/spacetime-vis/ + + +Made in R +========= + +![](images/vLine.svg) + +http://oscarperpinan.github.io/spacetime-vis/ + + +And it's very easy! +=================== +type: section + + +Map species occurrences in 2 lines of code +========================================== + +```{r echo=FALSE} +library(knitr) +library(dismo) +data(acaule) +acaule <- acaule[acaule$continent == "South America", ] +acaule <- acaule[!is.na(acaule$lat) | !is.na(acaule$lon), ] +acaule <- subset(acaule, select = c("species", "lon", "lat")) +crs.geo <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84") +occs <- acaule +acaule.sp <- acaule +coordinates(acaule.sp) <- c("lon", "lat") +crs(acaule.sp) <- crs.geo +occdata <- Mercator(acaule.sp) +``` + +```{r fig.keep = "last"} +plot(gmap(occdata, type = "satellite")) +points(occdata, col = "red", pch=20, cex = 2) +``` + + + +Let's go step by step +===================== +type: section + + +A dataframe of species occurrences +================================== + +```{r echo=FALSE} +kable(head(occs)) +``` + + +Make it a spatial object +======================== + +```{r} +coordinates(occs) <- c("lon", "lat") +str(occs, 2) +``` + + +Specify projection (CRS) +======================== + +```{r} +crs(occs) <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84") +``` + +See http://spatialreference.org + + +Project to Mercator and plot +============================ + +```{r fig.keep = "last"} +plot(gmap(occs, type = "satellite")) +points(Mercator(occs), col = "red", pch = 20, cex = 2) +``` + + +Alternatively, load shapefile +============================= + +```{r echo = FALSE} +shapefile(occs, filename = "occs.shp", overwrite = TRUE) +``` + +```{r fig.keep = "last"} +occs <- shapefile("occs.shp") +plot(gmap(occs, type = "satellite")) +points(Mercator(occs), col = "red", pch = 20, cex = 2) +``` + + +Using ggmap +=========== + +```{r eval=TRUE} +library(ggmap) +map <- get_map(bbox(occs), maptype = "watercolor", source = "stamen") +ggmap(map) + + geom_point(aes(x = coords.x1, y = coords.x2), data = as.data.frame(coordinates(occs)), + colour = "red", size = 4) +``` + + +Raster data +=========== +type: section + + +Download elevation data +========================== + +```{r} +elevation <- getData("alt", country = "ESP") +``` + +```{r} +library(rasterVis) +levelplot(elevation) +``` + + + +Dynamic interactive maps with leaflet +===================================== + +```{r} +library(mapview) +mapView(occs) +``` + + + +Remote sensing growing fast +=========================== + +e.g. RStoolbox + +![](images/rstoolbox.png) + + +Doing GIS in R: main advantages +=============================== +incremental: true + +- Fully-reproducible scripts + +- **Harness all R stats power** + + - Data wrangling + + - Modelling + + - Dataviz + +- Easy! + + + + +Calling GIS from R +================== + +- Grass: [`spgrass6`](http://www.rdocumentation.org/packages/spgrass6) +- SAGA: [`RSAGA`](http://www.rdocumentation.org/packages/RSAGA) +- ArcGIS: https://github.com/R-ArcGIS +![](images/R_ArcGis.png) + +Includes calling R from ArcGIS too + + + + +To read more +============ + +http://pakillo.github.io/R-GIS-tutorial + + + + + diff --git a/GISwithR.Rpres b/GISwithR.Rpres new file mode 100644 index 0000000..e975ab6 --- /dev/null +++ b/GISwithR.Rpres @@ -0,0 +1,234 @@ +GIS with R: slides for the unconverted +======================================================== +author: Francisco Rodriguez-Sanchez +date: @frod_san +2015-11-14 + + +R: not only for stats +===================== + +![](images/R.jpg) + + +R can make beautiful maps +========================= +type: section + + + +Made in R +========== + +![](images/bike_ggplot.png) + +http://spatial.ly/2012/02/great-maps-ggplot2/ + + +Made in R +========= + +![](images/facebook_map.png) + +http://paulbutler.org/archives/visualizing-facebook-friends/ + + +Made in R +========= + +![](images/airMadrid_stamen.png) + +http://oscarperpinan.github.io/spacetime-vis/ + + +Made in R +========= + +![](images/cft.png) + +http://oscarperpinan.github.io/spacetime-vis/ + + +Made in R +========= + +![](images/vLine.svg) + +http://oscarperpinan.github.io/spacetime-vis/ + + +And it's very easy! +=================== +type: section + + +Map species occurrences in 2 lines of code +========================================== + +```{r echo=FALSE} +library(knitr) +library(dismo) +data(acaule) +acaule <- acaule[acaule$continent == "South America", ] +acaule <- acaule[!is.na(acaule$lat) | !is.na(acaule$lon), ] +acaule <- subset(acaule, select = c("species", "lon", "lat")) +crs.geo <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84") +occs <- acaule +acaule.sp <- acaule +coordinates(acaule.sp) <- c("lon", "lat") +crs(acaule.sp) <- crs.geo +occdata <- Mercator(acaule.sp) +``` + +```{r fig.keep = "last"} +plot(gmap(occdata, type = "satellite")) +points(occdata, col = "red", pch=20, cex = 2) +``` + + + +Let's go step by step +===================== +type: section + + +A dataframe of species occurrences +================================== + +```{r echo=FALSE} +kable(head(occs)) +``` + + +Make it a spatial object +======================== + +```{r} +coordinates(occs) <- c("lon", "lat") +str(occs, 2) +``` + + +Specify projection (CRS) +======================== + +```{r} +crs(occs) <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84") +``` + +See http://spatialreference.org + + +Project to Mercator and plot +============================ + +```{r fig.keep = "last"} +plot(gmap(occs, type = "satellite")) +points(Mercator(occs), col = "red", pch = 20, cex = 2) +``` + + +Alternatively, load shapefile +============================= + +```{r echo = FALSE} +shapefile(occs, filename = "occs.shp", overwrite = TRUE) +``` + +```{r fig.keep = "last"} +occs <- shapefile("occs.shp") +plot(gmap(occs, type = "satellite")) +points(Mercator(occs), col = "red", pch = 20, cex = 2) +``` + + +Using ggmap +=========== + +```{r eval=TRUE} +library(ggmap) +map <- get_map(bbox(occs), maptype = "watercolor", source = "stamen") +ggmap(map) + + geom_point(aes(x = coords.x1, y = coords.x2), data = as.data.frame(coordinates(occs)), + colour = "red", size = 4) +``` + + +Raster data +=========== +type: section + + +Download elevation data +========================== + +```{r} +elevation <- getData("alt", country = "ESP") +``` + +```{r} +library(rasterVis) +levelplot(elevation) +``` + + + +Dynamic interactive maps with leaflet +===================================== + +```{r} +library(mapview) +mapView(occs) +``` + + + +Remote sensing growing fast +=========================== + +e.g. RStoolbox + +![](images/rstoolbox.png) + + +Doing GIS in R: main advantages +=============================== +incremental: true + +- Fully-reproducible scripts + +- **Harness all R stats power** + + - Data wrangling + + - Modelling + + - Dataviz + +- Easy! + + + + +Calling GIS from R +================== + +- Grass: [`spgrass6`](http://www.rdocumentation.org/packages/spgrass6) +- SAGA: [`RSAGA`](http://www.rdocumentation.org/packages/RSAGA) +- ArcGIS: https://github.com/R-ArcGIS +![](images/R_ArcGis.png) + +Includes calling R from ArcGIS too + + + + +To read more +============ + +http://pakillo.github.io/R-GIS-tutorial + + + + + diff --git a/GISwithR.html b/GISwithR.html new file mode 100644 index 0000000..316e094 --- /dev/null +++ b/GISwithR.html @@ -0,0 +1,1201 @@ + + + + + + GIS with R: slides for the unconverted + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+

GIS with R: slides for the unconverted

Francisco Rodriguez-Sanchez
@frod_san

+ +
+

2015-11-14

+ +
+ +
+
+

R: not only for stats

+
+

+ +
+ +
+
+

R can make beautiful maps

+
+ +
+ +
+
+

Made in R

+ + +
+
+

Made in R

+ + +
+
+

Made in R

+ + +
+
+

Made in R

+ + +
+
+

Made in R

+ + +
+
+

And it's very easy!

+
+ +
+ +
+
+

Map species occurrences in 2 lines of code

+
+
plot(gmap(occdata, type = "satellite"))
+points(occdata, col = "red", pch=20, cex = 2)
+
+ +

plot of chunk unnamed-chunk-2

+ +
+ +
+
+

Let's go step by step

+
+ +
+ +
+
+

A dataframe of species occurrences

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
specieslonlat
1Solanum acaule Bitter-66.10-21.90
2Solanum acaule Bitter-71.00-13.50
52Solanum acaule Bitter-66.43-24.22
53Solanum acaule Bitter-72.07-13.35
54Solanum acaule Bitter-68.97-15.23
55Solanum acaule Bitter-64.95-17.75
+ +
+ +
+
+

Make it a spatial object

+
+
coordinates(occs) <- c("lon", "lat")
+str(occs, 2)
+
+ +
Formal class 'SpatialPointsDataFrame' [package "sp"] with 5 slots
+  ..@ data       :'data.frame': 49 obs. of  1 variable:
+  ..@ coords.nrs : int [1:2] 2 3
+  ..@ coords     : num [1:49, 1:2] -66.1 -71 -66.4 -72.1 -69 ...
+  .. ..- attr(*, "dimnames")=List of 2
+  ..@ bbox       : num [1:2, 1:2] -72.5 -24.2 -64.7 -12.5
+  .. ..- attr(*, "dimnames")=List of 2
+  ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slot
+
+ +
+ +
+
+

Specify projection (CRS)

+
+
crs(occs) <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84")
+
+ +

See http://spatialreference.org

+ +
+ +
+
+

Project to Mercator and plot

+
+
plot(gmap(occs, type = "satellite"))
+points(Mercator(occs), col = "red", pch = 20, cex = 2)
+
+ +

plot of chunk unnamed-chunk-6

+ +
+ +
+
+

Alternatively, load shapefile

+
+
occs <- shapefile("occs.shp")
+plot(gmap(occs, type = "satellite"))
+points(Mercator(occs), col = "red", pch = 20, cex = 2)
+
+ +

plot of chunk unnamed-chunk-8

+ +
+ +
+
+

Using ggmap

+
+
library(ggmap)
+map <- get_map(bbox(occs), maptype = "watercolor", source = "stamen")
+ggmap(map) +
+  geom_point(aes(x = coords.x1, y = coords.x2), data = as.data.frame(coordinates(occs)),
+             colour = "red", size = 4)
+
+ +

plot of chunk unnamed-chunk-9

+ +
+ +
+
+

Raster data

+
+ +
+ +
+
+

Download elevation data

+
+
elevation <- getData("alt", country = "ESP")
+
+ +
library(rasterVis)
+levelplot(elevation)
+
+ +

plot of chunk unnamed-chunk-11

+ +
+ +
+
+

Dynamic interactive maps with leaflet

+
+
library(mapview)
+mapView(occs)
+
+ +
+ +
+
+

Remote sensing growing fast

+
+

e.g. RStoolbox

+ +

+ +
+ +
+
+

Doing GIS in R: main advantages

+
+
    +
  • Fully-reproducible scripts

  • +
  • Harness all R stats power

    + +
      +
    • Data wrangling
    • +
    • Modelling
    • +
    • Dataviz
    • +
  • +
  • Easy!

  • +
+ +
+ +
+
+

Calling GIS from R

+
+ + +

Includes calling R from ArcGIS too

+ +
+ +
+
+

To read more

+ + +
+ + +
+
+ + + + + + + + + + diff --git a/GISwithR.md b/GISwithR.md new file mode 100644 index 0000000..0e6f5eb --- /dev/null +++ b/GISwithR.md @@ -0,0 +1,257 @@ +GIS with R: slides for the unconverted +======================================================== +author: Francisco Rodriguez-Sanchez +date: @frod_san +2015-11-14 + + +R: not only for stats +===================== + +![](images/R.jpg) + + +R can make beautiful maps +========================= +type: section + + + +Made in R +========== + +![](images/bike_ggplot.png) + +http://spatial.ly/2012/02/great-maps-ggplot2/ + + +Made in R +========= + +![](images/facebook_map.png) + +http://paulbutler.org/archives/visualizing-facebook-friends/ + + +Made in R +========= + +![](images/airMadrid_stamen.png) + +http://oscarperpinan.github.io/spacetime-vis/ + + +Made in R +========= + +![](images/cft.png) + +http://oscarperpinan.github.io/spacetime-vis/ + + +Made in R +========= + +![](images/vLine.svg) + +http://oscarperpinan.github.io/spacetime-vis/ + + +And it's very easy! +=================== +type: section + + +Map species occurrences in 2 lines of code +========================================== + + + + +```r +plot(gmap(occdata, type = "satellite")) +points(occdata, col = "red", pch=20, cex = 2) +``` + +![plot of chunk unnamed-chunk-2](GISwithR-figure/unnamed-chunk-2-1.png) + + + +Let's go step by step +===================== +type: section + + +A dataframe of species occurrences +================================== + + +| |species | lon| lat| +|:--|:---------------------|------:|------:| +|1 |Solanum acaule Bitter | -66.10| -21.90| +|2 |Solanum acaule Bitter | -71.00| -13.50| +|52 |Solanum acaule Bitter | -66.43| -24.22| +|53 |Solanum acaule Bitter | -72.07| -13.35| +|54 |Solanum acaule Bitter | -68.97| -15.23| +|55 |Solanum acaule Bitter | -64.95| -17.75| + + +Make it a spatial object +======================== + + +```r +coordinates(occs) <- c("lon", "lat") +str(occs, 2) +``` + +``` +Formal class 'SpatialPointsDataFrame' [package "sp"] with 5 slots + ..@ data :'data.frame': 49 obs. of 1 variable: + ..@ coords.nrs : int [1:2] 2 3 + ..@ coords : num [1:49, 1:2] -66.1 -71 -66.4 -72.1 -69 ... + .. ..- attr(*, "dimnames")=List of 2 + ..@ bbox : num [1:2, 1:2] -72.5 -24.2 -64.7 -12.5 + .. ..- attr(*, "dimnames")=List of 2 + ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slot +``` + + +Specify projection (CRS) +======================== + + +```r +crs(occs) <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84") +``` + +See http://spatialreference.org + + +Project to Mercator and plot +============================ + + +```r +plot(gmap(occs, type = "satellite")) +points(Mercator(occs), col = "red", pch = 20, cex = 2) +``` + +![plot of chunk unnamed-chunk-6](GISwithR-figure/unnamed-chunk-6-1.png) + + +Alternatively, load shapefile +============================= + + + + +```r +occs <- shapefile("occs.shp") +plot(gmap(occs, type = "satellite")) +points(Mercator(occs), col = "red", pch = 20, cex = 2) +``` + +![plot of chunk unnamed-chunk-8](GISwithR-figure/unnamed-chunk-8-1.png) + + +Using ggmap +=========== + + +```r +library(ggmap) +map <- get_map(bbox(occs), maptype = "watercolor", source = "stamen") +ggmap(map) + + geom_point(aes(x = coords.x1, y = coords.x2), data = as.data.frame(coordinates(occs)), + colour = "red", size = 4) +``` + +![plot of chunk unnamed-chunk-9](GISwithR-figure/unnamed-chunk-9-1.png) + + +Raster data +=========== +type: section + + +Download elevation data +========================== + + +```r +elevation <- getData("alt", country = "ESP") +``` + + +```r +library(rasterVis) +levelplot(elevation) +``` + +![plot of chunk unnamed-chunk-11](GISwithR-figure/unnamed-chunk-11-1.png) + + + +Dynamic interactive maps with leaflet +===================================== + + +```r +library(mapview) +mapView(occs) +``` + +![plot of chunk unnamed-chunk-12](GISwithR-figure/unnamed-chunk-12-1.png) + + + +Remote sensing growing fast +=========================== + +e.g. RStoolbox + +![](images/rstoolbox.png) + + +Doing GIS in R: main advantages +=============================== +incremental: true + +- Fully-reproducible scripts + +- **Harness all R stats power** + + - Data wrangling + + - Modelling + + - Dataviz + +- Easy! + + + + +Calling GIS from R +================== + +- Grass: [`spgrass6`](http://www.rdocumentation.org/packages/spgrass6) +- SAGA: [`RSAGA`](http://www.rdocumentation.org/packages/RSAGA) +- ArcGIS: https://github.com/R-ArcGIS +![](images/R_ArcGis.png) + +Includes calling R from ArcGIS too + + + + +To read more +============ + +http://pakillo.github.io/R-GIS-tutorial + + + + + diff --git a/images/R.jpg b/images/R.jpg new file mode 100644 index 0000000..ba0b762 Binary files /dev/null and b/images/R.jpg differ diff --git a/images/R_ArcGis.PNG b/images/R_ArcGis.PNG new file mode 100644 index 0000000..7d5001d Binary files /dev/null and b/images/R_ArcGis.PNG differ diff --git a/images/airMadrid_stamen.png b/images/airMadrid_stamen.png new file mode 100644 index 0000000..777f7f1 Binary files /dev/null and b/images/airMadrid_stamen.png differ diff --git a/images/bike_ggplot.png b/images/bike_ggplot.png new file mode 100644 index 0000000..ac56143 Binary files /dev/null and b/images/bike_ggplot.png differ diff --git a/images/cft.png b/images/cft.png new file mode 100644 index 0000000..b205710 Binary files /dev/null and b/images/cft.png differ diff --git a/images/facebook_map.png b/images/facebook_map.png new file mode 100644 index 0000000..52e0320 Binary files /dev/null and b/images/facebook_map.png differ diff --git a/images/rstoolbox.png b/images/rstoolbox.png new file mode 100644 index 0000000..45a2e9a Binary files /dev/null and b/images/rstoolbox.png differ diff --git a/images/vLine.svg b/images/vLine.svg new file mode 100644 index 0000000..e888476 --- /dev/null +++ b/images/vLine.svg @@ -0,0 +1,448 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 40.35 + + ° + + + N + + + + + + + + + + + + + + + + 40.4 + + ° + + + N + + + + + + + + + + + + + + + + 40.45 + + ° + + + N + + + + + + + + + + + + + + + + 40.5 + + ° + + + N + + + + + + + + + + + + + + + + + + + + + + + + + + 3.75 + + ° + + + W + + + + + + + + + + + + + + + + 3.7 + + ° + + + W + + + + + + + + + + + + + + + + 3.65 + + ° + + + W + + + + + + + + + + + + + + + + 3.6 + + ° + + + W + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 20 + + + + + + + 40 + + + + + + + 60 + + + + + + + 80 + + + + + + + 100 + + + + + + + + + + + + + + + + + + ene + + + + + + + abr + + + + + + + jul + + + + + + + oct + + + + + + + ene + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file