Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 0 additions & 85 deletions R/aesthetics.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,88 +33,3 @@ detect_mixture <- function(sim_situation) {

return(is_mixture)
}

#' Detect items cases for dynamic plots
#'
#' This function detects the cases for computing the aesthetics of a plot based on
#' whether it is a mixture or not, whether it has one or multiple versions, and
#' whether there is any overlap.
#'
#' @param is_mixture A logical value indicating whether the crop is a mixture or not.
#' @param one_version A logical value indicating whether the plot has one or multiple versions (e.g. of the model).
#' @param overlap A logical value indicating whether there is any overlapping variables in the plot.
#'
#' @return A character string indicating the case for computing the aesthetics of the plot.
#'
#' @keywords internal
detect_mixture_version_overlap <- function(is_mixture, one_version, overlap) {
case <- switch(paste(is_mixture, !one_version, !is.null(overlap)),
"TRUE TRUE TRUE" = "mixture_versions_overlap",
"TRUE TRUE FALSE" = "mixture_versions_no_overlap",
"TRUE FALSE TRUE" = "mixture_no_versions_overlap",
"TRUE FALSE FALSE" = "mixture_no_versions_no_overlap",
"FALSE TRUE TRUE" = "non_mixture_versions_overlap",
"FALSE TRUE FALSE" = "non_mixture_versions_no_overlap",
"FALSE FALSE TRUE" = "non_mixture_no_versions_overlap",
"FALSE FALSE FALSE" = "non_mixture_no_versions_no_overlap"
)

return(case)
}

#' Detect items cases for scatter plots
#'
#' This function detects the cases for computing the aesthetics of a plot based on
#' whether it is a mixture or not, whether it has one or multiple versions, and
#' whether there are one or several situations to plot into the same plot.
#'
#' @param is_mixture A logical value indicating whether the crop is a mixture or not.
#' @param one_version A logical value indicating whether the plot has one or multiple versions (e.g. of the model).
#' @param has_distinct_situations A logical value indicating whether there are one or several situations to plot.
#'
#' @return A character string indicating the case for computing the aesthetics of the plot.
#'
#' @keywords internal
detect_mixture_version_situations <- function(is_mixture, one_version, has_distinct_situations) {
case <- switch(paste(is_mixture, !one_version, has_distinct_situations),
"TRUE TRUE TRUE" = "mixture_versions",
"TRUE TRUE FALSE" = "mixture_versions",
"TRUE FALSE TRUE" = "mixture_no_versions",
"TRUE FALSE FALSE" = "mixture_no_versions",
"FALSE TRUE TRUE" = "non_mixture_versions_situations",
"FALSE TRUE FALSE" = "non_mixture_versions_per_situations",
"FALSE FALSE TRUE" = "non_mixture_no_versions_situations",
"FALSE FALSE FALSE" = "non_mixture_no_versions_per_situations"
)

return(case)
}

#' Detect items cases
#'
#' This function returns a unique string based on the type of plot, and
#' whether the situation is a mixture or not, if there is one or multiple
#' versions to plot, and if there is one or several situations to plot
#' into the same plot.
#' The output is used to choose the right plotting function in a switch.
#'
#' @param type The type of plot required, either 'dynamic' or 'scatter
#' @param is_mixture A logical value indicating whether the crop is a mixture or not.
#' @param one_version A logical value indicating whether the plot has one or multiple versions (e.g. of the model).
#' @param has_distinct_situations A logical value indicating whether there are one or several situations to plot.
#' @param overlap A logical value indicating whether there is any overlapping variables in the plot.
#'
#' @return A unique character string for the plot.
#'
#' @keywords internal
detect_item_case <- function(type, is_mixture, one_version, has_distinct_situations, overlap) {
if (type == "dynamic") {
item_case <- detect_mixture_version_overlap(is_mixture, one_version, overlap)
} else if (type == "scatter") {
item_case <- detect_mixture_version_situations(is_mixture, one_version, has_distinct_situations)
} else {
stop("type must be either 'dynamic' or 'scatter'")
}

return(item_case)
}
79 changes: 14 additions & 65 deletions R/generic_plotting.R
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,6 @@ plot_situations <- function(..., obs = NULL, obs_sd = NULL,
for (i in common_situations_models) {
sim_situation <- formated_situation_list[[i]]
mixture <- detect_mixture(sim_situation)
item_case <- detect_item_case(
type, mixture, one_version, has_distinct_situations, overlap
)

plot_title <- if (!is.null(title)) {
title[[i]]
Expand All @@ -183,68 +180,20 @@ plot_situations <- function(..., obs = NULL, obs_sd = NULL,
i
}

p[[i]] <- switch(item_case,
# Dynamic plots:
"mixture_versions_overlap" =
plot_dynamic_mixture_versions_overlap(sim_situation, i, successive,
title = plot_title
),
"mixture_versions_no_overlap" =
plot_dynamic_mixture_versions(sim_situation, i, successive, title = plot_title),
"mixture_no_versions_overlap" =
plot_dynamic_mixture_overlap(sim_situation, i, successive, title = plot_title),
"mixture_no_versions_no_overlap" = plot_dynamic_mixture(sim_situation, i, successive,
title = plot_title
),
"non_mixture_versions_overlap" =
plot_dynamic_versions_overlap(sim_situation, i, successive, title = plot_title),
"non_mixture_versions_no_overlap" =
plot_dynamic_versions(sim_situation, i, successive, title = plot_title),
"non_mixture_no_versions_overlap" =
plot_dynamic_overlap(sim_situation, i, successive, title = plot_title),
"non_mixture_no_versions_no_overlap" =
plot_dynamic(sim_situation, i, successive, title = plot_title),

# Scatter plots:
"mixture_versions" =
plot_scat_mixture_versions( # per sit and all sit share the same call
sim_situation, i, select_scat, shape_sit,
reference_var, is_obs_sd,
title = plot_title
),
"mixture_no_versions" = # per sit and all sit share the same call
plot_scat_mixture_allsit(
sim_situation, i, select_scat, shape_sit,
reference_var, is_obs_sd,
title = plot_title
),
"non_mixture_versions_situations" =
plot_scat_versions_allsit(
sim_situation, i, select_scat, shape_sit,
reference_var, is_obs_sd,
title = plot_title
),
"non_mixture_versions_per_situations" =
plot_scat_versions_per_sit(
sim_situation, i, select_scat, shape_sit,
reference_var, is_obs_sd,
title = plot_title
),
"non_mixture_no_versions_situations" =
plot_scat_allsit(
sim_situation, i, select_scat, shape_sit,
reference_var, is_obs_sd,
title = plot_title, has_distinct_situations = has_distinct_situations,
one_version = one_version, mixture = mixture
),
"non_mixture_no_versions_per_situations" =
plot_scat_allsit(
sim_situation, i, select_scat, shape_sit,
reference_var, is_obs_sd,
title = plot_title, has_distinct_situations = has_distinct_situations,
one_version = one_version, mixture = mixture
)
)
if (type == "dynamic") {
p[[i]] <- build_dynamic_plot(
sim_situation, i, successive,
title = plot_title,
mixture, one_version, overlap
)
} else {
p[[i]] <- build_scatter_plot(
sim_situation, select_scat, shape_sit, reference_var, is_obs_sd,
title = plot_title,
mixture = mixture, one_version = one_version,
has_distinct_situations = has_distinct_situations
)
}
}

names(p) <- common_situations_models
Expand Down
Loading