From 19258a81dfbe24fc5c81650657d2633002faf08f Mon Sep 17 00:00:00 2001 From: acrunyon Date: Mon, 16 Aug 2021 13:42:17 -0600 Subject: [PATCH] add DEM to map plots --- Code/Plots/map_monthly_dotplots_pcp.R | 1 + Code/Plots/map_monthly_dotplots_tmax.R | 1 + Code/Plots/map_monthly_dotplots_tmean.R | 1 + Code/Plots/map_monthly_dotplots_tmin.R | 1 + Code/Plots/maps_ts_plots_MAMSON.SWE.R | 1 + Code/Plots/maps_ts_plots_SWE.precip.R | 1 + Code/Plots/maps_ts_plots_max.SWE.R | 1 + Code/Plots/maps_ts_plots_pcp.R | 1 + Code/Plots/maps_ts_plots_soil.temp.R | 1 + Code/Plots/maps_ts_plots_tmean.R | 3 ++- Code/Plots/maps_ts_plots_water.balance.R | 1 + plot-creation.Rmd | 20 +++++++++++++++----- 12 files changed, 27 insertions(+), 6 deletions(-) diff --git a/Code/Plots/map_monthly_dotplots_pcp.R b/Code/Plots/map_monthly_dotplots_pcp.R index 5cf695e..9750d91 100644 --- a/Code/Plots/map_monthly_dotplots_pcp.R +++ b/Code/Plots/map_monthly_dotplots_pcp.R @@ -38,6 +38,7 @@ scale.max = max(c(DJF.cf1$pcp_in,MAM.cf1$pcp_in,JJA.cf1$pcp_in,SON.cf1$pcp_in, # ggplot map.plot <- function(data, title,xaxis,metric,col){ ggplot() + + geom_raster(data = ak_df ,aes(x = x, y = y,alpha=HYP_HR_SR_W.1), show.legend=FALSE) + geom_stars(data = data, alpha = 0.8) + geom_sf(data = shp, aes(), fill = NA) + scale_fill_viridis(direction=-1, option = scale, diff --git a/Code/Plots/map_monthly_dotplots_tmax.R b/Code/Plots/map_monthly_dotplots_tmax.R index 23f16a7..9d690af 100644 --- a/Code/Plots/map_monthly_dotplots_tmax.R +++ b/Code/Plots/map_monthly_dotplots_tmax.R @@ -38,6 +38,7 @@ scale.max = max(c(DJF.cf1$mean,MAM.cf1$mean,JJA.cf1$mean,SON.cf1$mean, # ggplot map.plot <- function(data, title,xaxis,metric,col){ ggplot() + + geom_raster(data = ak_df ,aes(x = x, y = y,alpha=HYP_HR_SR_W.1), show.legend=FALSE) + geom_stars(data = data, alpha = 0.8) + geom_sf(data = shp, aes(), fill = NA) + scale_fill_viridis(direction=1, option = scale, diff --git a/Code/Plots/map_monthly_dotplots_tmean.R b/Code/Plots/map_monthly_dotplots_tmean.R index 75f516f..6e1d2b7 100644 --- a/Code/Plots/map_monthly_dotplots_tmean.R +++ b/Code/Plots/map_monthly_dotplots_tmean.R @@ -38,6 +38,7 @@ scale.max = max(c(DJF.cf1$mean,MAM.cf1$mean,JJA.cf1$mean,SON.cf1$mean, # ggplot map.plot <- function(data, title,xaxis,metric,col){ ggplot() + + geom_raster(data = ak_df ,aes(x = x, y = y,alpha=HYP_HR_SR_W.1), show.legend=FALSE) + geom_stars(data = data, alpha = 0.8) + geom_sf(data = shp, aes(), fill = NA) + scale_fill_viridis(direction=1, option = scale, diff --git a/Code/Plots/map_monthly_dotplots_tmin.R b/Code/Plots/map_monthly_dotplots_tmin.R index f3ec7ac..613dad3 100644 --- a/Code/Plots/map_monthly_dotplots_tmin.R +++ b/Code/Plots/map_monthly_dotplots_tmin.R @@ -38,6 +38,7 @@ scale.max = max(c(DJF.cf1$mean,MAM.cf1$mean,JJA.cf1$mean,SON.cf1$mean, # ggplot map.plot <- function(data, title,xaxis,metric,col){ ggplot() + + geom_raster(data = ak_df ,aes(x = x, y = y,alpha=HYP_HR_SR_W.1), show.legend=FALSE) + geom_stars(data = data, alpha = 0.8) + geom_sf(data = shp, aes(), fill = NA) + scale_fill_viridis(direction=1, option = scale, diff --git a/Code/Plots/maps_ts_plots_MAMSON.SWE.R b/Code/Plots/maps_ts_plots_MAMSON.SWE.R index aeb4e71..b324dd2 100644 --- a/Code/Plots/maps_ts_plots_MAMSON.SWE.R +++ b/Code/Plots/maps_ts_plots_MAMSON.SWE.R @@ -33,6 +33,7 @@ scale.max = max(c(cf1$mean,cf2$mean,cf3$mean),na.rm=TRUE) # ggplot map.plot <- function(data, title,xaxis,metric,col){ ggplot() + + geom_raster(data = ak_df ,aes(x = x, y = y,alpha=HYP_HR_SR_W.1), show.legend=FALSE) + geom_stars(data = data, alpha = 0.8) + geom_sf(data = shp, aes(), fill = NA) + scale_fill_viridis(direction=1, option = scale, diff --git a/Code/Plots/maps_ts_plots_SWE.precip.R b/Code/Plots/maps_ts_plots_SWE.precip.R index b616eb8..fff1c5a 100644 --- a/Code/Plots/maps_ts_plots_SWE.precip.R +++ b/Code/Plots/maps_ts_plots_SWE.precip.R @@ -33,6 +33,7 @@ scale.max = max(c(cf1$mean,cf2$mean,cf3$mean),na.rm=TRUE) # ggplot map.plot <- function(data, title,xaxis,metric,col){ ggplot() + + geom_raster(data = ak_df ,aes(x = x, y = y,alpha=HYP_HR_SR_W.1), show.legend=FALSE) + geom_stars(data = data, alpha = 0.8) + geom_sf(data = shp, aes(), fill = NA) + scale_fill_viridis(direction=1, option = scale, diff --git a/Code/Plots/maps_ts_plots_max.SWE.R b/Code/Plots/maps_ts_plots_max.SWE.R index d7dec6b..3f6b342 100644 --- a/Code/Plots/maps_ts_plots_max.SWE.R +++ b/Code/Plots/maps_ts_plots_max.SWE.R @@ -34,6 +34,7 @@ scale.max = max(c(cf1$mean,cf2$mean,cf3$mean),na.rm=TRUE) # ggplot map.plot <- function(data, title,xaxis,metric,col){ ggplot() + + geom_raster(data = ak_df ,aes(x = x, y = y,alpha=HYP_HR_SR_W.1), show.legend=FALSE) + geom_stars(data = data, alpha = 0.8) + geom_sf(data = shp, aes(), fill = NA) + scale_fill_viridis(direction=1, option = scale, diff --git a/Code/Plots/maps_ts_plots_pcp.R b/Code/Plots/maps_ts_plots_pcp.R index 493d732..bd5c3d4 100644 --- a/Code/Plots/maps_ts_plots_pcp.R +++ b/Code/Plots/maps_ts_plots_pcp.R @@ -33,6 +33,7 @@ scale.max = max(c(cf1$mean,cf2$mean,cf3$mean),na.rm=TRUE) # ggplot map.plot <- function(data, title,xaxis,metric,col){ ggplot() + + geom_raster(data = ak_df ,aes(x = x, y = y,alpha=HYP_HR_SR_W.1), show.legend=FALSE) + geom_stars(data = data, alpha = 0.8) + geom_sf(data = shp, aes(), fill = NA) + scale_fill_viridis(direction=-1, option = scale, diff --git a/Code/Plots/maps_ts_plots_soil.temp.R b/Code/Plots/maps_ts_plots_soil.temp.R index 8dbdf08..ae67c2a 100644 --- a/Code/Plots/maps_ts_plots_soil.temp.R +++ b/Code/Plots/maps_ts_plots_soil.temp.R @@ -34,6 +34,7 @@ scale.max = max(c(cf1$mean,cf2$mean,cf3$mean),na.rm=TRUE) # ggplot map.plot <- function(data, title,xaxis,metric,col){ ggplot() + + geom_raster(data = ak_df ,aes(x = x, y = y,alpha=HYP_HR_SR_W.1), show.legend=FALSE) + geom_stars(data = data, alpha = 0.8) + geom_sf(data = shp, aes(), fill = NA) + scale_fill_viridis(direction=1, option = scale, diff --git a/Code/Plots/maps_ts_plots_tmean.R b/Code/Plots/maps_ts_plots_tmean.R index fb02d35..38d8f27 100644 --- a/Code/Plots/maps_ts_plots_tmean.R +++ b/Code/Plots/maps_ts_plots_tmean.R @@ -32,7 +32,8 @@ scale.max = max(c(cf1$mean,cf2$mean,cf3$mean),na.rm=TRUE) # ggplot map.plot <- function(data, title,xaxis,metric,col){ - ggplot() + + ggplot() + + geom_raster(data = ak_df ,aes(x = x, y = y,alpha=HYP_HR_SR_W.1), show.legend=FALSE) + geom_stars(data = data, alpha = 0.8) + geom_sf(data = shp, aes(), fill = NA) + scale_fill_viridis(direction=1, option = scale, diff --git a/Code/Plots/maps_ts_plots_water.balance.R b/Code/Plots/maps_ts_plots_water.balance.R index 61c3dea..3c6e67f 100644 --- a/Code/Plots/maps_ts_plots_water.balance.R +++ b/Code/Plots/maps_ts_plots_water.balance.R @@ -34,6 +34,7 @@ scale.max = max(c(cf1$mean,cf2$mean,cf3$mean),na.rm=TRUE) # ggplot map.plot <- function(data, title,xaxis,metric,col){ ggplot() + + geom_raster(data = ak_df ,aes(x = x, y = y,alpha=HYP_HR_SR_W.1), show.legend=FALSE) + geom_stars(data = data, alpha = 0.8) + geom_sf(data = shp, aes(), fill = NA) + scale_fill_viridis(direction=-1, option = scale, diff --git a/plot-creation.Rmd b/plot-creation.Rmd index 0b380d9..720d549 100644 --- a/plot-creation.Rmd +++ b/plot-creation.Rmd @@ -12,7 +12,7 @@ knitr::opts_chunk$set(echo = TRUE) ```{r set directories, include=FALSE, results=hide, eval=TRUE} rm(list = ls()) -library(stars);library(dplyr);library(ggplot2);library(ggthemes);library(viridis);library(here);library(ggrepel);library(rlang);library(units); library(tidyr); library(lemon);library(ggpubr);library(gridExtra);library(grid); library(gtable); library(lubridate) +library(stars);library(dplyr);library(ggplot2);library(ggthemes);library(viridis);library(here);library(ggrepel);library(rlang);library(units); library(tidyr); library(lemon);library(ggpubr);library(gridExtra);library(grid); library(gtable); library(lubridate);library(raster) base.dir = "C:/Users/achildress/Documents/wrst_temp" data.dir = paste0(base.dir,"/Data") @@ -22,6 +22,15 @@ boundary.dir <- "C:/Users/achildress/DOI/NPS-WRST-Resource Stewardship Strategy wrst <- st_read(paste0(boundary.dir, "wrst_simple.shp")) # Wrangell Mountains wrst <- st_transform(wrst, 3338) +# insert topo +topo <- stack(paste0(boundary.dir, 'HYP_HR_SR_W/HYP_HR_SR_W.tif')) # read in as stack so can see RBG layers +ext <- extent(-147, -139, 59.3, 63) # extent defined by lat/long +ak <- crop(topo, ext) +# plotRGB(ak) +ak2 <- projectRaster(ak, crs = CRS('+init=EPSG:3338')) # Alaska Albers +ak_df <- as.data.frame(ak2, xy = TRUE) # this step is important to get it to plot in ggplot + + GCMs <- c("inmcm4.rcp85","ACCESS1-3.rcp45","CanESM2.rcp85") CFs <- c("Climate Future 1", "Climate Future 2", "Climate Future 3") cols <- c("#12045C","#ffcccc","#E10720") @@ -35,10 +44,6 @@ CF_GCM <- data.frame(CF=CFs,GCM=GCMs,CF_col=cols) ``` ```{r scatterplot, echo=FALSE, message=FALSE, warning=FALSE,eval=FALSE} -# source(here::here("Code", "Plots", "scatterplot.R"),echo = FALSE) -``` - -```{r seasonal plots, include=FALSE,results=hide, eval=TRUE} dir = paste0(data.dir,"/WRST_simple/") df = read.csv(paste0(dir,"/Monthly_met.csv")) @@ -71,6 +76,11 @@ df.fut = subset(DF, Period=="Future" & GCM %in% GCMs) delta = df.hist[,1:4] delta[,5:8] = df.fut[,5:8] - df.hist[,5:8] +# source(here::here("Code", "Plots", "scatterplot.R"),echo = FALSE) +``` + +```{r seasonal plots, include=FALSE,results=hide, eval=TRUE} + source(here::here("Code", "Plots", "map_monthly_dotplots_tmax.R"),echo = FALSE) source(here::here("Code", "Plots", "map_monthly_dotplots_tmin.R"),echo = FALSE) source(here::here("Code", "Plots", "map_monthly_dotplots_tmean.R"),echo = FALSE)