ggmap

Etienne Low-Décarie

Creating maps

if(!require(ggmap)) {install.packages("ggmap")}
require(ggmap)
if(!require(maptools)) {install.packages("maptools")}
require(maptools)

Basic world map

map <- ggplot()+borders("world", 
                        colour="gray50",
                        fill="gray50")
print(map)

plot of chunk unnamed-chunk-2

Resource

Cheatsheet: https://www.nceas.ucsb.edu/~frazier/RSpatialGuides/ggmap/ggmapCheatsheet.pdf

Pretty world map

bounding box lowerleftlon, lowerleftlat, upperrightlon, upperrightlat (a little glitchy for google maps)

myLocation <- with(coord, c(min(LON),
                            min(LAT), 
                            max(LON), 
                            max(LAT)))
myLocation <- c(-179,-89,179,89)
myMap <- get_map(location=myLocation, 
                 source="stamen", 
                 maptype="watercolor",
                 crop=FALSE) 

myMap <- ggmap(myMap)
print(myMap)

plot of chunk unnamed-chunk-4

Load geo-referenced coral bleaching data

Coral bleaching data from ReefBase http://www.reefbase.org

coord <- read.csv("./Data/CoralBleaching_cleaned.csv")

Extract bleaching events

coord <- coord[coord$BLEACHING_SEVERITY %in% c("Low","Medium","HIGH"),]
coord$BLEACHING_SEVERITY <- factor(coord$BLEACHING_SEVERITY, levels=levels(coord$BLEACHING_SEVERITY)[c(2,3,1)])

Add the data to the map

map <- map+geom_point(data=coord,aes(x=LON,
                                     y=LAT,
                                     colour=BLEACHING_SEVERITY),
                      alpha=0.5)
print(map)

plot of chunk unnamed-chunk-7

Fine tuning: Scales

map <- map+
  scale_colour_manual(values = c("Low"="yellow",
                                 "Medium"="orange",
                                 "HIGH"="red"))+
  guides(colour = guide_legend(override.aes = list(alpha = 1))) #+
  #facet_grid(YEAR~.)

print(map)

plot of chunk unnamed-chunk-8

Fine tuning: Facets

print(map+facet_wrap(~YEAR))

plot of chunk unnamed-chunk-9

Exercise 1

Create a coordinate file with the location of your house and the location of the house of your friends

Produce maps from the data in Henry P, Le Lay G, Goudet J, Guisan A, Jahodová S, Besnard G (2009) Reduced genetic diversity, increased isolation and multiple introductions of invasive giant hogweed in the western Swiss Alps. Molecular Ecology 18: 2819-2831. paper data