Skip to content

Commit

Permalink
Merge branch 'state_level_initial_fixFigures' of github.com:USEPA/FrE…
Browse files Browse the repository at this point in the history
…DI into state_level_initial_fixFigures
  • Loading branch information
tonygard-indecon committed Dec 18, 2023
2 parents 899e847 + be72272 commit bbd8b1a
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 123 deletions.
6 changes: 3 additions & 3 deletions FrEDI/R/utils_create_report_figures.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions FrEDI/R/utils_plot_DOW_byImpactTypes.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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)

Expand Down Expand Up @@ -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
Expand Down
14 changes: 11 additions & 3 deletions FrEDI/R/utils_plot_DOW_bySector.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
230 changes: 116 additions & 114 deletions FrEDI/scripts/create_DoW_results.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -299,43 +300,44 @@ 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()
sum_gcm_byType |>
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)



Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand Down

0 comments on commit bbd8b1a

Please sign in to comment.