Skip to content

Instantly share code, notes, and snippets.

@jebyrnes
Created October 6, 2018 03:10
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 jebyrnes/a6234254536177fd46705563f880f6d3 to your computer and use it in GitHub Desktop.
Save jebyrnes/a6234254536177fd46705563f880f6d3 to your computer and use it in GitHub Desktop.
SST change in the lambert projection
library(raster)
#devtools::install_github("jebyrnes/hadsstr")
library(hadsstr) #from jebyrnes/hadsstr
library(ggplot2)
library(sf)
library(rnaturalearth)
#get the world in the lambert projection
countries_50_sf <- ne_download(scale = 50, category = 'cultural', type = 'countries', returnclass="sf")
countries_lambert <- st_transform(oceans, 2154)
#load in the hadsst data - downloaded from
#https://www.metoffice.gov.uk/hadobs/hadisst/data/download.html
#as a netcdf
hadsst <- brick("HadISST_sst.nc")
raster::NAvalue(hadsst) <- -1000
#get linear change and reproject to lambert projection
hadsst_change <- get_sst_linear_change(hadsst, years = 1950:2016)
hadsst_change_lambert <- projectRaster(hadsst_change, crs = "+proj=lcc +lat_1=49 +lat_2=44 +lat_0=46.5 +lon_0=3 +x_0=700000 +y_0=6600000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs") #lambert CRS
hadsst_change_lambert <- crop(hadsst_change_lambert, extent(countries_lambert))
hadsst_change_df <- as.data.frame(hadsst_change_lambert, xy=TRUE)
#plot it
ggplot() +
geom_raster(data = hadsst_change_df, mapping = aes(x=x, y=y, fill=layer)) +
geom_sf(data = countries_lambert, fill="lightgrey", color=NA, alpha=0.5) +
scale_fill_gradient2(low = "blue", high = "red", mid = "white", midpoint = 0) +
#coord_cartesian()
coord_sf(xlim=c(-5e07,5e07), ylim=c(-3.7e07, 5.2e07)) #zoom - can futz with this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment