Skip to content

Instantly share code, notes, and snippets.

@fawda123
Created May 6, 2018 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fawda123/bcad2ca3cad529eee6e0d53217dd8a60 to your computer and use it in GitHub Desktop.
Save fawda123/bcad2ca3cad529eee6e0d53217dd8a60 to your computer and use it in GitHub Desktop.
meuse exercise
# load libraries
library(sp) # for meuse
library(sf) # for sf objects
library(ggmap) # for base maps
library(ggplot2) # for mapping
# import dataset, check structure
data(meuse)
str(meuse)
# convert to sf object
dat <- st_as_sf(meuse, coords = c('x', 'y'), crs = "+init=epsg:28992")
# change the coordinate system to geographic
dat <- st_transform(dat, crs = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
# get base map from ggmap
datext <- unname(st_bbox(dat))
bsmap <- get_map(location = datext, maptype = 'satellite', zoom = 13)
# make the plot
ggmap(bsmap) +
geom_sf(data = dat, inherit.aes = F)
# map cadmium to colour, change colour scale
ggmap(bsmap) +
geom_sf(data = dat, inherit.aes = F, aes(colour = cadmium)) +
scale_colour_distiller(type = 'div', palette = 9)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment