From 1bca60a17931d68f03f2ba3b8ff4b703a904c093 Mon Sep 17 00:00:00 2001 From: Karen Noiva Date: Mon, 18 Dec 2023 16:09:00 -0500 Subject: [PATCH 1/4] Update utils_plot_DOW_byImpactTypes.R Replaced deprecated functions (e.g. replaced addListNames with set_names) --- FrEDI/R/utils_plot_DOW_byImpactTypes.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/FrEDI/R/utils_plot_DOW_byImpactTypes.R b/FrEDI/R/utils_plot_DOW_byImpactTypes.R index 6b35034e..ca384930 100644 --- a/FrEDI/R/utils_plot_DOW_byImpactTypes.R +++ b/FrEDI/R/utils_plot_DOW_byImpactTypes.R @@ -220,7 +220,7 @@ plot_DOW_byImpactTypes <- function( }) ### Name the plots - listVars_j <- listVars_j |> addListNames(c_variants) + listVars_j <- listVars_j |> set_names(c_variants) # return(listVars_j) # "got here1..." |> print() @@ -245,7 +245,7 @@ plot_DOW_byImpactTypes <- function( ### Name the plots # listTypes_i |> length() |> print(); c_impTypes |> print() - listTypes_i <- listTypes_i |> addListNames(c_impTypes) + listTypes_i <- listTypes_i |> set_names(c_impTypes) # "got here3..." |> print() # return(listTypes_i) @@ -284,7 +284,7 @@ plot_DOW_byImpactTypes <- function( return(plotGrid_i) }) ### Name the plots - listYears0 <- listYears0 |> addListNames(c_impYears) + listYears0 <- listYears0 |> set_names(c_impYears) ###### Return ###### ### Return the plot From 68c1e57131c528e10de034f982422175186b27be Mon Sep 17 00:00:00 2001 From: Karen Noiva Date: Mon, 18 Dec 2023 16:09:38 -0500 Subject: [PATCH 2/4] Update utils_plot_DOW_bySector.R Created a manual shape palette since there are now more than 6 models --- FrEDI/R/utils_plot_DOW_bySector.R | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/FrEDI/R/utils_plot_DOW_bySector.R b/FrEDI/R/utils_plot_DOW_bySector.R index 3f3ff6ae..7b22e64f 100644 --- a/FrEDI/R/utils_plot_DOW_bySector.R +++ b/FrEDI/R/utils_plot_DOW_bySector.R @@ -84,17 +84,25 @@ plot_DOW_bySector <- function( if(!hasMUnits){mUnit0 <- "cm"} ###### Create the plot ###### - # df0 %>% names() %>% print() - # df0 %>% glimpse() + # df0 |> names() |> print() + # df0 |> glimpse() plot0 <- df0 |> ggplot(aes(x=.data[[xCol]], y=.data[[yCol]])) + # plot0 <- df0 |> ggplot(aes(x=.data[[xCol]], y=.data[[yCol]], group=interaction(sector, model))) ### Add Geoms plot0 <- plot0 + geom_line (aes(color = model)) + # plot0 <- plot0 + geom_point(aes(color = model)) plot0 <- plot0 + geom_point(aes(color = model, shape=model)) ### Add Scales plot0 <- plot0 + scale_color_discrete(lgdTitle0) - plot0 <- plot0 + scale_shape_discrete(lgdTitle0) + # plot0 <- plot0 + scale_shape_discrete(lgdTitle0) + shapeLvls <- df0[["model"]] |> unique() |> sort() + numShapes <- shapeLvls |> length() + shapeVals <- c(1:numShapes) + # shapeLvls |> print() + # plot0 <- plot0 + scale_shape_discrete(lgdTitle0) + plot0 <- plot0 + scale_shape_manual(lgdTitle0, breaks=shapeLvls, values=shapeVals) plot0 <- plot0 + scale_x_continuous(xTitle0, limits = x_limits, breaks = x_breaks) plot0 <- plot0 + scale_y_continuous(yTitle0, limits = y_limits, breaks = y_breaks) From fb7b5ece750f3e83eb59c9409c7333254066f992 Mon Sep 17 00:00:00 2001 From: Karen Noiva Date: Mon, 18 Dec 2023 16:14:31 -0500 Subject: [PATCH 3/4] Update utils_create_report_figures.R Small changes to spaces --- FrEDI/R/utils_create_report_figures.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/FrEDI/R/utils_create_report_figures.R b/FrEDI/R/utils_create_report_figures.R index 652c4d82..f94462e2 100644 --- a/FrEDI/R/utils_create_report_figures.R +++ b/FrEDI/R/utils_create_report_figures.R @@ -839,13 +839,13 @@ plot_DoW <- function( bind_rows() df_types <- df_types |> rbind(df_gcm) rm(df_gcm) - } + } ### if(do_gcm) ### SLR data if(do_slr){ df_slr <- tibble(type="SLR", year="all", label="SLR" |> paste0("_", "all")) df_types <- df_types |> rbind(df_slr) rm(df_slr) - } + } ### if(do_slr) # "got here" |> print() # df_types |> glimpse() @@ -854,7 +854,7 @@ plot_DoW <- function( ### Initialize list list0 <- pList0 %>% pmap(function(x1, x2){ x1 |> paste0("_", x2) |> print() - plot_y <- plot_DoW_by_modelYear( + plot_y <- plot_DoW_by_modelYear( df0 = df0, ### Data (e.g., output from sum_impactsByDegree) type0 = x1, ### Model type: GCM or SLR year0 = x2, From 790596cd7e7d0cf0f967694cd8a53992a6185dbd Mon Sep 17 00:00:00 2001 From: Karen Noiva Date: Mon, 18 Dec 2023 16:19:28 -0500 Subject: [PATCH 4/4] Update create_DoW_results.R Extended integer degrees from 7 to 10 degrees Fixed figure code and added it back in --- FrEDI/scripts/create_DoW_results.R | 230 +++++++++++++++-------------- 1 file changed, 116 insertions(+), 114 deletions(-) diff --git a/FrEDI/scripts/create_DoW_results.R b/FrEDI/scripts/create_DoW_results.R index 39aca94b..656902b2 100644 --- a/FrEDI/scripts/create_DoW_results.R +++ b/FrEDI/scripts/create_DoW_results.R @@ -121,7 +121,8 @@ create_DoW_results <- function( conusPrefix0 <- "Other_Integer" globalPrefix0 <- "preI_global" ### Temperatures - c_conusTemps <- 0:7 + # c_conusTemps <- 0:7 + c_conusTemps <- 0:10 c_globalTemps <- c(1.487, 2.198) ### Numbers of scenarios n_conusTemps <- c_conusTemps |> length() @@ -254,36 +255,36 @@ create_DoW_results <- function( } ### End if(saveFile) # return(list(x=c_scen_con, y=c_scen_glo, z=df_int_totals, w=sum_gcm_totals)) - # ###### ** -- Plots - # #### Create plots - # ### Scale isn't the same across sectors - # # codePath |> loadCustomFunctions() - # if(testing|do_msg) "Plotting GCM results by sector, degree of warming (DOW)..." |> message() - # plots_dow_gcm <- sum_gcm_totals |> plot_DoW( - # types0 = c("GCM"), ### Model type: GCM or SLR - # years = gcmYears, - # xCol = "driverValue", - # yCol = "annual_impacts", - # thresh0 = breakChars - # ) - # ### Glimpse - # if(return0) resultsList[["plots_dow_gcm"]] <- plots_dow_gcm - # if(testing) plots_dow_gcm[["GCM_2010"]] |> print() - # ### Save - # # codePath |> loadCustomFunctions() - # if(saveFile){ - # if(do_msg) paste0("Saving plots of GCM results by sector, degree of warming...") |> message() - # ### Save plots as Rdata - # plots_dow_gcm |> save_data(fpath = fig7ResultsPath, fname = "gcm_fig7_plots", ftype = "rda") - # - # ### Save plots as image files - # saved0 <- plots_dow_gcm |> save_fig7_images( - # modelType = "GCM", - # fpath = fig7ResultsPath, - # device = img_dev, - # units = imgUnits - # ) - # } ### End if(saveFile) + ###### ** -- Plots + #### Create plots + ### Scale isn't the same across sectors + # codePath |> loadCustomFunctions() + if(testing|do_msg) "Plotting GCM results by sector, degree of warming (DOW)..." |> message() + plots_dow_gcm <- sum_gcm_totals |> plot_DoW( + types0 = c("GCM"), ### Model type: GCM or SLR + years = gcmYears, + xCol = "driverValue", + yCol = "annual_impacts", + thresh0 = breakChars + ) + ### Glimpse + if(testing) plots_dow_gcm[["GCM_2090"]] |> print() + if(return0) resultsList[["plots_dow_gcm"]] <- plots_dow_gcm + ### Save + # codePath |> loadCustomFunctions() + if(saveFile){ + if(do_msg) paste0("Saving plots of GCM results by sector, degree of warming...") |> message() + ### Save plots as Rdata + plots_dow_gcm |> save_data(fpath = fig7ResultsPath, fname = "gcm_fig7_plots", ftype = "rda") + + ### Save plots as image files + saved0 <- plots_dow_gcm |> save_fig7_images( + modelType = "GCM", + fpath = fig7ResultsPath, + device = img_dev, + units = imgUnits + ) + } ### End if(saveFile) ###### ** Appendix Figs: DoW By Type ###### # codePath |> loadCustomFunctions() @@ -299,8 +300,8 @@ create_DoW_results <- function( silent = TRUE ) ### Glimpse - if(return0) resultsList[["sum_gcm_byType"]] <- sum_gcm_byType if(testing) sum_gcm_byType |> glimpse() + if(return0) resultsList[["sum_gcm_byType"]] <- sum_gcm_byType ### Save summary table if(saveFile){ if(do_msg) paste0("Saving summary of GCM results by sector, impact type, degree of warming...") |> message() @@ -308,34 +309,35 @@ create_DoW_results <- function( save_data(fpath = appxResultsPath, fname = "gcm_results_byDoW_byType", ftype = "csv", row.names = F) } ### End if(saveFile) - # ### Create Plots - # # codePath |> loadCustomFunctions() - # if(testing|do_msg) "Plotting GCM results by sector, impact type, degree of warming (DOW)..." |> message() - # plots_gcm_byType <- sum_gcm_byType |> - # # filter(sector %in% c_sectorNames[c(10)]) |> - # plot_DoW_by_sector( - # models = c("GCM"), - # yCol = "annual_impacts" - # ) - # ### Glimpse - # if(return0) resultsList[["plots_gcm_byType"]] <- plots_gcm_byType - # if(testing) plots_gcm_byType$GCM$`Extreme Temperature_2010`[["2010"]] |> print() - # ### Save - # if(saveFile){ - # if(do_msg) paste0("Saving plots of GCM results by sector, impact type, degree of warming...") |> message() - # ### Save plots as a data object - # plots_gcm_byType |> save_data(fpath = appxResultsPath, fname = "gcm_appendix_plots", ftype = "rda") - # - # ### Save plots as image files - # saved0 <- plots_gcm_byType |> save_appendix_figures( - # df0 = sum_gcm_byType, - # modelType = "GCM", ### Or SLR - # fpath = appxResultsPath, - # device = img_dev, - # res = imgRes, - # units = imgUnits - # ) ### End save_appendix_figures - # } ### End if(saveFile) + ### Create Plots + # codePath |> loadCustomFunctions() + if(testing|do_msg) "Plotting GCM results by sector, impact type, degree of warming (DOW)..." |> message() + plots_gcm_byType <- sum_gcm_byType |> + # filter(sector %in% c_sectorNames[c(10)]) |> + filter(!(sector %in% c("Roads"))) |> + plot_DoW_by_sector( + models = c("GCM"), + yCol = "annual_impacts" + ) + ### Glimpse + if(testing) plots_gcm_byType$GCM$`Extreme Temperature_2010`[["2010"]] |> print() + if(return0) resultsList[["plots_gcm_byType"]] <- plots_gcm_byType + ### Save + if(saveFile){ + if(do_msg) paste0("Saving plots of GCM results by sector, impact type, degree of warming...") |> message() + ### Save plots as a data object + plots_gcm_byType |> save_data(fpath = appxResultsPath, fname = "gcm_appendix_plots", ftype = "rda") + + ### Save plots as image files + saved0 <- plots_gcm_byType |> save_appendix_figures( + df0 = sum_gcm_byType, + modelType = "GCM", ### Or SLR + fpath = appxResultsPath, + device = img_dev, + res = imgRes, + units = imgUnits + ) ### End save_appendix_figures + } ### End if(saveFile) @@ -435,33 +437,33 @@ create_DoW_results <- function( save_data(fpath = fig7ResultsPath, fname = "slr_results_byDoW_totals", ftype = "csv", row.names = F) } ### End if(saveFile) - # ###### ** -- Plots - # ### Create the plots - # # codePath |> loadCustomFunctions() - # if(testing|do_msg) "Plotting SLR results by sector, year, GMSL (cm)..." |> message() - # plots_dow_slr <- sum_slr_totals |> plot_DoW( - # types0 = c("SLR"), ### Model type: GCM or SLR - # yCol = "annual_impacts", - # nCol = 2, - # thresh0 = breakChars - # ) - # ### Glimpse - # if(return0) resultsList[["plots_dow_slr"]] <- plots_dow_slr - # if(testing) plots_dow_slr[["SLR_all"]] |> print() - # ### Save - # if(saveFile){ - # if(do_msg) paste0("Saving plots of SLR results by sector, year, GMSL (cm)...") |> message() - # ### Save plots as a data object - # plots_dow_slr |> save_data(fpath = fig7ResultsPath, fname = "slr_fig7_plots", ftype = "rda") - # - # ### Save plots as image files - # plots_dow_slr |> save_fig7_images( - # modelType = "SLR", ### Or SLR - # fpath = fig7ResultsPath, - # device = img_dev, - # units = imgUnits - # ) - # } ### End if(saveFile) + ###### ** -- Plots + ### Create the plots + # codePath |> loadCustomFunctions() + if(testing|do_msg) "Plotting SLR results by sector, year, GMSL (cm)..." |> message() + plots_dow_slr <- sum_slr_totals |> plot_DoW( + types0 = c("SLR"), ### Model type: GCM or SLR + yCol = "annual_impacts", + nCol = 2, + thresh0 = breakChars + ) + ### Glimpse + if(return0) resultsList[["plots_dow_slr"]] <- plots_dow_slr + if(testing) plots_dow_slr[["SLR_all"]] |> print() + ### Save + if(saveFile){ + if(do_msg) paste0("Saving plots of SLR results by sector, year, GMSL (cm)...") |> message() + ### Save plots as a data object + plots_dow_slr |> save_data(fpath = fig7ResultsPath, fname = "slr_fig7_plots", ftype = "rda") + + ### Save plots as image files + plots_dow_slr |> save_fig7_images( + modelType = "SLR", ### Or SLR + fpath = fig7ResultsPath, + device = img_dev, + units = imgUnits + ) + } ### End if(saveFile) ###### ** Appendix Figs: DoW By Type ###### # codePath |> loadCustomFunctions() @@ -484,33 +486,33 @@ create_DoW_results <- function( save_data(fpath = appxResultsPath, fname = "slr_results_byDoW_byType", ftype = "csv", row.names = F) } ### End if(saveFile) - # ### Create SLR plots - # # codePath |> loadCustomFunctions() - # if(testing|do_msg) "Plotting SLR results by sector, impact type, GMSL (cm)..." |> message() - # plots_slr_byType <- sum_slr_byType |> plot_DoW_by_sector( - # models = c("SLR"), - # xCol = "year", - # yCol = "annual_impacts" - # ) - # ### Glimpse - # if(return0) resultsList[["plots_slr_byType"]] <- plots_slr_byType - # if(testing) plots_slr_byType$SLR$`Coastal Properties_all`[[1]] |> print() - # ### Save - # if(saveFile){ - # if(do_msg) paste0("Saving plot of SLR scenarios by sector, impact type, GMSL (cm)...") |> message() - # ### Save plots as a data object - # plots_slr_byType |> save_data(fpath = appxResultsPath, fname = "slr_appendix_plots", ftype = "rda") - # - # ### Save plots as image files - # saved0 <- plots_slr_byType |> save_appendix_figures( - # df0 = sum_slr_byType, - # modelType = "SLR", ### Or SLR - # fpath = appxResultsPath, - # device = img_dev, - # res = imgRes, - # units = imgUnits - # ) ### End save_appendix_figures - # } ### End if(saveFile) + ### Create SLR plots + # codePath |> loadCustomFunctions() + if(testing|do_msg) "Plotting SLR results by sector, impact type, GMSL (cm)..." |> message() + plots_slr_byType <- sum_slr_byType |> plot_DoW_by_sector( + models = c("SLR"), + xCol = "year", + yCol = "annual_impacts" + ) + ### Glimpse + if(return0) resultsList[["plots_slr_byType"]] <- plots_slr_byType + if(testing) plots_slr_byType$SLR$`Coastal Properties_all`[[1]] |> print() + ### Save + if(saveFile){ + if(do_msg) paste0("Saving plot of SLR scenarios by sector, impact type, GMSL (cm)...") |> message() + ### Save plots as a data object + plots_slr_byType |> save_data(fpath = appxResultsPath, fname = "slr_appendix_plots", ftype = "rda") + + ### Save plots as image files + saved0 <- plots_slr_byType |> save_appendix_figures( + df0 = sum_slr_byType, + modelType = "SLR", ### Or SLR + fpath = appxResultsPath, + device = img_dev, + res = imgRes, + units = imgUnits + ) ### End save_appendix_figures + } ### End if(saveFile) ###### Return ###### return(resultsList)