diff --git a/R/plot_impact.R b/R/plot_impact.R index ebf20860494ffa8c2be6e1bb8e1acf00550c43b7..f0a2614ce9ce4b8d67cf50b22eea0a6bb223f152 100644 --- a/R/plot_impact.R +++ b/R/plot_impact.R @@ -20,8 +20,6 @@ #' @importFrom scales pretty_breaks #' @import ggplot2 #' -#' @examples -#' #' plot_impact <- function(N, onset_year = NULL, percent = TRUE, xlab = "Year", ylab = "Relative impact (%)", Legend = NULL, ...){ @@ -75,7 +73,8 @@ plot_impact <- function(N, onset_year = NULL, percent = TRUE, xlab = "Year", yla breaks = scales::pretty_breaks(n = 10), sec.axis = sec_axis(trans = ~.*1, name = "", breaks = scales::pretty_breaks(n = 10))) + - scale_x_continuous(expand = c(0,0)) + scale_x_continuous(expand = expansion(mult = c(0.015, 0)), + breaks = scales::pretty_breaks(n = 10)) # Add horizontal dashed lines (for better viz) p <- p + geom_hline(yintercept = seq(0 , -100, by = -10), size = 0.5, linetype = 3, colour = grey(0.15)) diff --git a/R/plot_traj.R b/R/plot_traj.R index 96eb7a194afb709e1bd6b1f53fe7fb279a9cbc49..17e53affb9bb9df8bb080f78b1c5dc51a64d8773 100644 --- a/R/plot_traj.R +++ b/R/plot_traj.R @@ -6,8 +6,6 @@ #' @param N a 4-D array containing demographic projection outputs #' @param onset_year a vector containing the years of each wind farm start being active #' (thus, the year at whihc each fatality value starts kicking in) -#' @param percent a logical value indicating whether the impact should be displayed in % (y axis). -#' If FALSE, the impact value displayed is between 0 and -1 (negative impact). #' @param xlab a character string. Label for the x axis. #' @param ylab a character string. Label for the y axis. #' @param Legend a vector of character strings. The legend to show on the side of the plot. @@ -20,10 +18,9 @@ #' @importFrom scales pretty_breaks #' @import ggplot2 #' -#' @examples #' #' -plot_traj <- function(N, onset_year = NULL, percent = TRUE, xlab = "Year", ylab = "Relative impact (%)", +plot_traj <- function(N, onset_year = NULL, xlab = "Year", ylab = "Relative impact (%)", Legend = NULL, ...){ # Get metrics and dimensions @@ -83,7 +80,9 @@ plot_traj <- function(N, onset_year = NULL, percent = TRUE, xlab = "Year", ylab # Add y-axis on right side, and make pretty x/y axis and limits p <- p + scale_y_continuous(expand = expansion(mult = c(0.025, 0.005)), - breaks = scales::pretty_breaks(n = 10)) + + breaks = scales::pretty_breaks(n = 10), + sec.axis = sec_axis(trans = ~.*1, name = "", + breaks = scales::pretty_breaks(n = 10))) + scale_x_continuous(expand = expansion(mult = c(0.015, 0)), breaks = scales::pretty_breaks(n = 10)) diff --git a/inst/ShinyApp/server.R b/inst/ShinyApp/server.R index 78c55c542f241e8d47b020c788147af4d569e256..e31c64e0dcf8ca12dddea176553d1d172e8bf840 100644 --- a/inst/ShinyApp/server.R +++ b/inst/ShinyApp/server.R @@ -1375,8 +1375,15 @@ server <- function(input, output, session){ ## Function to plot the impact plot_out_impact <- function(){ if(is.null(out$run)) {} else { + + n_scen <- dim(out$run$N)[3] + Legend <- NULL + if(out$analysis_choice == "single_farm") Legend <- c("Sans parc", "Avec parc") + if(out$analysis_choice == "cumulated") Legend <- c("Sans parc", "+ Parc 1", paste("... + Parc", (3:n_scen)-1)) + if(out$analysis_choice == "multi_scenario") Legend <- paste("Scenario", (1:n_scen)-1) + plot_impact(N = out$run$N, onset_year = param$onset_year, percent = TRUE, - xlab = "\nAnn�e", ylab = "Impact relatif (%)\n") + xlab = "\nAnn�e", ylab = "Impact relatif (%)\n", Legend = Legend) } } @@ -1397,7 +1404,15 @@ server <- function(input, output, session){ plot_out_traj <- function(){ if(is.null(out$run)) { } else { - plot_traj(N = out$run$N, xlab = "Ann�e", ylab = "Taille de population (toutes classes d'�ges)")} + + n_scen <- dim(out$run$N)[3] + Legend <- NULL + if(out$analysis_choice == "single_farm") Legend <- c("Sans parc", "Avec parc") + if(out$analysis_choice == "cumulated") Legend <- c("Sans parc", "+ Parc 1", paste("... + Parc", (3:n_scen)-1)) + if(out$analysis_choice == "multi_scenario") Legend <- paste("Scenario", (1:n_scen)-1) + + plot_traj(N = out$run$N, onset_year = param$onset_year, + xlab = "\nAnn�e", ylab = "Taille de population\n", Legend = Legend)} } output$title_traj_plot <- renderText({ diff --git a/man/plot_impact.Rd b/man/plot_impact.Rd index 3018f936e941888b0d06863baf8c42440496b7f7..285883ccca52723aefbdea00a9b99294183f69b9 100644 --- a/man/plot_impact.Rd +++ b/man/plot_impact.Rd @@ -37,7 +37,3 @@ a plot of the relative impact of each scenario. \description{ Plot the relative impact for each scenario } -\examples{ - - -} diff --git a/man/plot_traj.Rd b/man/plot_traj.Rd index d094bbf49f13c9e5414dcc77610fef6e4100cc50..e872f32dce84b36971f7e34b0d656e3f9438a562 100644 --- a/man/plot_traj.Rd +++ b/man/plot_traj.Rd @@ -7,7 +7,6 @@ plot_traj( N, onset_year = NULL, - percent = TRUE, xlab = "Year", ylab = "Relative impact (\%)", Legend = NULL, @@ -20,9 +19,6 @@ plot_traj( \item{onset_year}{a vector containing the years of each wind farm start being active (thus, the year at whihc each fatality value starts kicking in)} -\item{percent}{a logical value indicating whether the impact should be displayed in \% (y axis). -If FALSE, the impact value displayed is between 0 and -1 (negative impact).} - \item{xlab}{a character string. Label for the x axis.} \item{ylab}{a character string. Label for the y axis.} @@ -37,7 +33,3 @@ a plot of the relative impact of each scenario. \description{ Plot demographic trajectories } -\examples{ - - -} diff --git a/run_analysis.R b/run_analysis.R index 696c3ab87bbaba870541a60b2b6a3e33d4dc4faf..afad34c5569f64d4dc9160d277d1b204762ca4f5 100644 --- a/run_analysis.R +++ b/run_analysis.R @@ -7,7 +7,7 @@ library(magrittr) library(eolpop) ## Inputs -nsim = 100 +nsim = 10 pop_size_mean = 50 pop_size_se = 0 @@ -118,6 +118,9 @@ colSums(N) %>% apply(., c(1,2), mean) out = list() out$run = run0 + +dim(out$run$N) + get_metrics(N = out$run$N)$scenario$impact[time_horzion, ,-1] %>% round(.,2) res = get_metrics(N = out$run$N, cumulated_impacts = cumulated_impacts)