Skip to content
Snippets Groups Projects
Commit 6900d95d authored by thierrychambert's avatar thierrychambert
Browse files

plots improvements

parent 1ae5f17f
No related branches found
No related tags found
No related merge requests found
......@@ -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))
......
......@@ -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))
......
......@@ -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 = "\nAnne", ylab = "Impact relatif (%)\n")
xlab = "\nAnne", 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 = "Anne", 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 = "\nAnne", ylab = "Taille de population\n", Legend = Legend)}
}
output$title_traj_plot <- renderText({
......
......@@ -37,7 +37,3 @@ a plot of the relative impact of each scenario.
\description{
Plot the relative impact for each scenario
}
\examples{
}
......@@ -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{
}
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment