Created
May 6, 2018 16:51
-
-
Save fawda123/bcad2ca3cad529eee6e0d53217dd8a60 to your computer and use it in GitHub Desktop.
meuse exercise
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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