knitr::opts_chunk$set( comment = "#>", echo=T, warning=F, message=F, fig.width=9, fig.height=6 )
library(dplyr); library(ggplot2); library(sf)
# Load shapefile of Switzerland data("che", package="sdc")
Here, I perform a first analysis of the SRTM elevation Data for Switzerland.
The elevation data for Switzerland (srtm3_che_1arc.rda, srtm_csi_che_3arc.rda), which I use here, can be downloaded from https://github.com/RS-eco/sdc/blob/master/data/.
The code for how the elevation data was created can be found here: https://github.com/RS-eco/sdc/blob/master/data-raw/srtm_che.R
data("srtm_csi_che_3arc", package="sdc") #colnames(srtm_csi_che_3arc) # Plot SRTM CSI altitude srtm_csi_che_3arc %>% ggplot() + geom_tile(aes(x=x, y=y, fill=altitude)) + geom_sf(data=che, fill="NA") + scale_fill_gradientn(name="Elevation (m)", colors=terrain.colors(255)) + coord_sf(expand=F) + theme_bw() + labs(x="", y="") rm(srtm_csi_che_3arc); invisible(gc()) data("srtm3_che_3arc", package="sdc") colnames(srtm3_che_3arc) head(srtm3_che_3arc) # Plot SRTM3 altitude srtm3_che_3arc %>% ggplot() + geom_tile(aes(x=x, y=y, fill=altitude)) + geom_sf(data=che, fill="NA") + scale_fill_gradientn(name="Elevation (m)", colors=terrain.colors(255)) + coord_sf(expand=F) + labs(x="", y="") + theme_bw() rm(srtm3_che_3arc); invisible(gc())
# Turn into ~ 9 km raster library(raster) data("srtm_csi_che_3arc", package="sdc") srtm_csi_che_3arc <- rasterFromXYZ(srtm_csi_che_3arc); gc() alt_che_mean <- aggregate(srtm_csi_che_3arc, fact=100, fun=mean, expand=T, na.rm=T) alt_che_median <- aggregate(srtm_csi_che_3arc, fact=100, fun=median, expand=T, na.rm=T) alt_che_min <- aggregate(srtm_csi_che_3arc, fact=100, fun=min, expand=T, na.rm=T) alt_che_max <- aggregate(srtm_csi_che_3arc, fact=100, fun=max, expand=T, na.rm=T) alt_che_sd <- aggregate(srtm_csi_che_3arc, fact=100, fun=sd, expand=T, na.rm=T) alt_che_9km <- stack(alt_che_mean, alt_che_median, alt_che_min, alt_che_max, alt_che_sd) rm(srtm_csi_che_3arc); gc() # Turn into data.frame alt_che_9km <- as.data.frame(rasterToPoints(alt_che_9km)); gc() colnames(alt_che_9km) <- c("x", "y", "alt_mean", "alt_median", "alt_min", "alt_max", "alt_sd") library(ggplot2) alt_che_9km %>% tidyr::pivot_longer(names_to="var", values_to="val", -c(x,y)) %>% filter(var %in% c("alt_mean", "alt_median", "alt_min", "alt_max")) %>% ggplot() + geom_tile(aes(x=x, y=y, fill=val)) + facet_wrap(.~var, ncol=2) + geom_sf(data=che, fill="NA") + scale_fill_gradientn(name="", colors=terrain.colors(255)) + coord_sf(expand=F) + labs(x="", y="") + theme_bw() rm(list=ls()); invisible(gc())
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.