quick maps in r

16
Office of Research and Development Pacific Coast Ecology Branch, Western Ecology Division Quick maps in R Melanie Frazier, NCEAS Presentation materials here: http://nceas.ucsb.edu/~frazier/RSpatialG uides/ggmap/

Upload: muncel

Post on 21-Mar-2016

47 views

Category:

Documents


6 download

DESCRIPTION

Quick maps in R. Melanie Frazier, NCEAS. Presentation materials here: http://nceas.ucsb.edu/~frazier/RSpatialGuides/ggmap/. Have Lat/Long data?. And, you want to see where they are. Data from the EPA’s WestuRe project: http://www.epa.gov/wed/pages/models/WestuRe/WestuRe.htm. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Quick maps in R

Quick maps in R

Melanie Frazier, NCEAS

Presentation materials here:http://nceas.ucsb.edu/~frazier/RSpatialGuides/ggmap/

Page 2: Quick maps in R

2

Have Lat/Long data?

And, you want to see where they are

Data from the EPA’s WestuRe project:http://www.epa.gov/wed/pages/models/WestuRe/WestuRe.htm

Page 3: Quick maps in R

Many options: But we’ll stick with 2

library(ggmap)library(plotKML)

Page 4: Quick maps in R

4

ggmap

Part 1

Download the map raster

Part 2

Overlay data onto raster

Refer to Quickstart guide:

Page 5: Quick maps in R

5

ggmap: Part 1 (getting the map)

A. Specify coordinates- geocodemyLocation <- “University of Washington”

- Lat/LongmyLocation <- c(lon=-95.36, lat=29.76)- Bounding box

(lowerleftlon, lowerleftlat, upperrightlon, upperrightlat) myLocation <- c(-130, 30, -105, 50)[NOTE: glitchy for google maps]

Page 6: Quick maps in R

6

B. Define map source, maptype, and color

sourcestamen

google

osm

maptype = watercolor toner terrain

terrain satellite roadmap hybrid

colorcan do any of the maps in

“bw”(and, cloudmade)

ggmap: Part 1 (getting the map)

Page 7: Quick maps in R

7

B. Define map source, maptype, and color

Scale matters in regard to map source/type

ggmap: Part 1 (getting the map)

Page 8: Quick maps in R

B. get_map function provides a general approach for quickly getting maps

myMap <- get_map(location = myLocation,source = “stamen”,maptype = “watercolor”,color = “bw”)

Additional options such as “zoom” and “crop” ?ggmap

ggmap: Part 1 (getting the map)

Page 9: Quick maps in R

Sometimes get_map doesn’t provide the control needed to get the map you want.

In this case, use the specific functions designed for the different map sources:

get_googlemapget_openstreetmapget_stamenmapget_cloudmademap

ggmap: Part 1 (getting the map)

Page 10: Quick maps in R

ggmap: Part 2 (overlaying your data)

A. Plot the rasterggmap(myMap)

B. Get your lat/long point data:myData <- read.csv(“http://nceas.ucsb.edu/~frazier/RSpatialGuides/ggmap/EstuaryData.csv”)

C. Add points (ggplot2 syntax)ggmap(myMap)+geom_point(aes(x=estLongitude, y=estLatitude), data=myData, alpha=0.5,

color=“darkred”, size=3)

Page 11: Quick maps in R

ggmaps: Part 2

Page 12: Quick maps in R

ggmaps: Part 2

Page 13: Quick maps in R

ggmap: Additional options

Page 15: Quick maps in R

plotKML

Tutorial:http://gsif.isric.org/doku.php?id=wiki:tutorial_plotkml

Load libraries: library(plotKML) library(sp)Convert to spatial dataframe object: coordinates(myData) <- ~estLongitude+estLatitudeProvide the projection (just copy this): proj4string(myData) <- CRS("+proj=longlat +datum=WGS84")Make the plot: plotKML(myData, colour="lnEstArea", balloon=TRUE)

Page 16: Quick maps in R

Questions

Presentation materials here:http://nceas.ucsb.edu/~frazier/RSpatialGuides/ggmap/