From 6431345140f822ee1356f30210e4c5912b5440f1 Mon Sep 17 00:00:00 2001 From: Valentine Rahier Date: Wed, 7 Oct 2026 14:38:12 +0200 Subject: [PATCH 1/6] refactor: refactor plots generation --- R/generic_plotting.R | 111 ++++--- R/specific_plotting_dynamic.R | 402 +++++++------------------ R/specific_plotting_scatter.R | 535 +++++++--------------------------- man/specific_dynamic_plots.Rd | 3 - man/specific_scatter_plots.Rd | 33 ++- 5 files changed, 295 insertions(+), 789 deletions(-) diff --git a/R/generic_plotting.R b/R/generic_plotting.R index 006e954..0c70891 100644 --- a/R/generic_plotting.R +++ b/R/generic_plotting.R @@ -183,68 +183,55 @@ 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]] <- switch(item_case, + # 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 + ) + ) + } } names(p) <- common_situations_models diff --git a/R/specific_plotting_dynamic.R b/R/specific_plotting_dynamic.R index 8fae437..377239f 100644 --- a/R/specific_plotting_dynamic.R +++ b/R/specific_plotting_dynamic.R @@ -94,329 +94,151 @@ make_multiline_title <- function(title, max_char = 120) { paste(lines, collapse = "\n") } -#' @keywords internal -#' @rdname specific_dynamic_plots -plot_dynamic <- function(df_data, sit, successive, title = NULL) { - p <- ggplot2::ggplot( - df_data, - ggplot2::aes(x = .data$Date) - ) + - ggplot2::geom_line(ggplot2::aes(y = .data$Simulated)) - - p <- add_vertical_lines(df_data, successive, p) - - if ("Observed" %in% colnames(df_data)) { - p <- p + ggplot2::geom_point(ggplot2::aes(y = .data$Observed), na.rm = TRUE) - - if ("Obs_SD" %in% colnames(df_data)) { - p <- p + - ggplot2::geom_errorbar( - ggplot2::aes( - ymin = .data$Observed - 2 * .data$Obs_SD, - ymax = .data$Observed + 2 * .data$Obs_SD - ), - na.rm = TRUE - ) - } - } - title <- make_multiline_title(title) - p <- p + - ggplot2::ggtitle(title) + - ggplot2::theme_get() - p <- add_facet_wrap(p, var = "var", scales = "free_y") - - return(p) -} - -plot_dynamic_mixture <- function(df_data, sit, successive, title = NULL) { - p <- ggplot2::ggplot( - df_data, - ggplot2::aes( - x = .data$Date, - colour = paste(.data$Dominance, ":", .data$Plant) - ) - ) + - ggplot2::geom_line(ggplot2::aes(y = .data$Simulated)) - - p <- add_vertical_lines(df_data, successive, p) - - if ("Observed" %in% colnames(df_data)) { - p <- p + ggplot2::geom_point(ggplot2::aes(y = .data$Observed), na.rm = TRUE) - - if ("Obs_SD" %in% colnames(df_data)) { - p <- p + - ggplot2::geom_errorbar( - ggplot2::aes( - ymin = .data$Observed - 2 * .data$Obs_SD, - ymax = .data$Observed + 2 * .data$Obs_SD - ), - na.rm = TRUE - ) - } - } - - title <- make_multiline_title(title) - p <- p + - ggplot2::ggtitle(title) + - ggplot2::labs(colour = "Plant") + - ggplot2::theme_get() - p <- add_facet_wrap( - p, - var = "var", scales = "free_y", - legend_labels = unique(paste(df_data$Dominance, ":", df_data$Plant)) +dynamic_plot_spec <- function(df_data, mixture, one_version, overlap) { + spec_name <- paste( + if (mixture) "mixture" else "sole", + if (one_version) "one_version" else "versions", + if (is.null(overlap)) "no_overlap" else "overlap", + sep = "_" ) - return(p) -} -plot_dynamic_mixture_overlap <- function(df_data, sit, successive, title = NULL) { - p <- ggplot2::ggplot( - df_data, - ggplot2::aes( - x = .data$Date, - colour = .data$var, - linetype = paste(.data$Dominance, ": ", .data$Plant), - shape = paste(.data$Dominance, ": ", .data$Plant) - ) - ) + - ggplot2::geom_line(ggplot2::aes(y = .data$Simulated)) - - p <- add_vertical_lines(df_data, successive, p) - - if ("Observed" %in% colnames(df_data)) { - p <- p + ggplot2::geom_point( - ggplot2::aes( - y = .data$Observed, - shape = paste( - .data$Dominance, - ": ", .data$Plant - ), - color = .data$var, + switch( + spec_name, + mixture_one_version_no_overlap = list( + mapping = ggplot2::aes(colour = paste(.data$Dominance, ":", .data$Plant)), + scales = "free_y", facets = "var", + extra = list(ggplot2::labs(colour = "Plant")), + legend_labels = unique(paste(df_data$Dominance, ":", df_data$Plant)) + ), + mixture_one_version_overlap = list( + mapping = ggplot2::aes( + colour = .data$var, + linetype = paste(.data$Dominance, ": ", .data$Plant), + shape = paste(.data$Dominance, ": ", .data$Plant) ), - na.rm = TRUE - ) - if ("Obs_SD" %in% colnames(df_data)) { - p <- p + - ggplot2::geom_errorbar( - ggplot2::aes( - ymin = .data$Observed - 2 * .data$Obs_SD, - ymax = .data$Observed + 2 * .data$Obs_SD - ), - na.rm = TRUE + facets = "group_var", + obs_mapping = ggplot2::aes( + shape = paste(.data$Dominance, ": ", .data$Plant), + color = .data$var + ), + extra = list( + ggplot2::guides( + colour = ggplot2::guide_legend(title = "Variable"), + linetype = ggplot2::guide_legend(title = "Plant", order = 1), + shape = ggplot2::guide_legend(title = "Plant", order = 1) ) - } - } - - title <- make_multiline_title(title) - p <- p + - ggplot2::ggtitle(title) + - ggplot2::guides( - colour = ggplot2::guide_legend(title = "Variable"), - # add override.aes = list(shape = NA) in prev guide_legend? - linetype = ggplot2::guide_legend(title = "Plant", order = 1), - shape = ggplot2::guide_legend(title = "Plant", order = 1) - ) + - ggplot2::theme_get() - p <- add_facet_wrap( - p, "group_var", - scales = "free", - legend_labels = c( - unique(as.character(df_data$var)), - unique(paste(df_data$Dominance, ": ", df_data$Plant)) - ) - ) - return(p) -} - -plot_dynamic_versions <- function(df_data, sit, successive, title = NULL) { - df_data$Observed_Legend <- "Observed Value" - p <- ggplot2::ggplot( - df_data, - ggplot2::aes(x = .data$Date, colour = .data$version) - ) + - ggplot2::geom_line(ggplot2::aes(y = .data$Simulated)) - - p <- add_vertical_lines(df_data, successive, p) - - if ("Observed" %in% colnames(df_data)) { - p <- p + ggplot2::geom_point( - ggplot2::aes(y = .data$Observed, shape = .data$Observed_Legend), - # NB: the shape is constant, but used to have a legend entry - color = "black", - na.rm = TRUE - ) - if ("Obs_SD" %in% colnames(df_data)) { - p <- p + - ggplot2::geom_errorbar( - ggplot2::aes( - ymin = .data$Observed - 2 * .data$Obs_SD, - ymax = .data$Observed + 2 * .data$Obs_SD, - shape = .data$version + ), + legend_labels = c( + unique(as.character(df_data$var)), + unique(paste(df_data$Dominance, ": ", df_data$Plant)) + ) + ), + sole_one_version_no_overlap = list(scales = "free_y", facets = "var"), + sole_one_version_overlap = list( + mapping = ggplot2::aes(colour = .data$var), + facets = "group_var", + obs_mapping = ggplot2::aes(shape = .data$var), + extra = list( + ggplot2::labs(colour = "Variable", shape = "Variable") + ), + legend_labels = unique(as.character(df_data$var)) + ), + sole_versions_no_overlap = list( + mapping = ggplot2::aes(colour = .data$version), + facets = "var", + obs_mapping = ggplot2::aes(shape = "Observed Value"), + obs_params = list(color = "black"), + extra = list( + ggplot2::guides( + colour = ggplot2::guide_legend( + title = "Version", + override.aes = list(shape = NA) ), - na.rm = TRUE + shape = ggplot2::guide_legend(title = "Observations") ) - } - } - - title <- make_multiline_title(title) - p <- p + - ggplot2::ggtitle(title) + - ggplot2::guides( - colour = ggplot2::guide_legend( - title = "Version", - override.aes = list(shape = NA) ), - shape = ggplot2::guide_legend(title = "Observations") - ) + - ggplot2::theme_get() - p <- add_facet_wrap( - p, - var = "var", scales = "free", - legend_labels = c(unique(df_data$version), "Observed Value") - ) - return(p) -} - -plot_dynamic_overlap <- function(df_data, sit, successive, title = NULL) { - p <- ggplot2::ggplot( - df_data, - ggplot2::aes(x = .data$Date, colour = .data$var) - ) + - ggplot2::geom_line(ggplot2::aes(y = .data$Simulated)) - - p <- add_vertical_lines(df_data, successive, p) - - if ("Observed" %in% colnames(df_data)) { - p <- p + - ggplot2::labs(shape = "Variable") + - ggplot2::geom_point( - ggplot2::aes(y = .data$Observed, shape = .data$var), - na.rm = TRUE + legend_labels = c(unique(df_data$version), "Observed Value") + ), + sole_versions_overlap = list( + mapping = ggplot2::aes( + colour = .data$var, + linetype = .data$version + ), + facets = "group_var", + obs_mapping = ggplot2::aes(colour = .data$var), + extra = list( + ggplot2::labs(colour = "Variable", linetype = "Version") + ), + legend_labels = c( + unique(as.character(df_data$var)), + unique(df_data$version) ) - if ("Obs_SD" %in% colnames(df_data)) { - p <- p + - ggplot2::geom_errorbar( - ggplot2::aes( - ymin = .data$Observed - 2 * .data$Obs_SD, - ymax = .data$Observed + 2 * .data$Obs_SD, - shape = .data$version - ), - na.rm = TRUE + ), + mixture_versions_no_overlap = list( + mapping = ggplot2::aes( + colour = paste(.data$Dominance, ":", .data$Plant), + linetype = .data$version + ), + facets = "var", + extra = list( + ggplot2::labs( + colour = "Plant", + linetype = "Version" ) - } - } - title <- make_multiline_title(title) - p <- p + - ggplot2::labs(colour = "Variable") + - ggplot2::ggtitle(title) + - ggplot2::theme_get() - p <- add_facet_wrap( - p, - var = "group_var", scales = "free", - legend_labels = unique(as.character(df_data$var)) - ) - return(p) -} - -plot_dynamic_mixture_versions_overlap <- function(df_data, sit, successive, title = NULL) { - stop( - "Too many cases to consider at a time: mixture + versions + overlap. ", - "Please use only a maximum of two combinations of: ", - "mixture, versions, overlap." + ), + legend_labels = c( + unique(paste(df_data$Dominance, ":", df_data$Plant)), + unique(df_data$version) + ) + ), + mixture_versions_overlap = stop( + "Too many cases to consider at a time: mixture + versions + overlap. ", + "Please use only a maximum of two combinations of: ", + "mixture, versions, overlap." + ) ) } - -plot_dynamic_versions_overlap <- function(df_data, sit, successive, title = NULL) { +build_dynamic_plot <- function(df_data, sit, successive, title = NULL, + mixture, one_version, overlap) { + spec <- dynamic_plot_spec(df_data,mixture, one_version, overlap) p <- ggplot2::ggplot( df_data, - ggplot2::aes( - x = .data$Date, colour = .data$var, - linetype = .data$version - ) + ggplot2::aes(x = .data$Date, !!!spec$mapping) ) + ggplot2::geom_line(ggplot2::aes(y = .data$Simulated)) p <- add_vertical_lines(df_data, successive, p) if ("Observed" %in% colnames(df_data)) { - p <- p + ggplot2::geom_point( - ggplot2::aes(y = .data$Observed, colour = .data$var), - na.rm = TRUE + p <- p + do.call( + ggplot2::geom_point, + c( + list( + mapping = ggplot2::aes(y = .data$Observed, !!!spec$obs_mapping), + na.rm = TRUE + ), + spec$obs_params + ) ) if ("Obs_SD" %in% colnames(df_data)) { p <- p + ggplot2::geom_errorbar( ggplot2::aes( ymin = .data$Observed - 2 * .data$Obs_SD, - ymax = .data$Observed + 2 * .data$Obs_SD, - colour = .data$var + ymax = .data$Observed + 2 * .data$Obs_SD ), na.rm = TRUE ) } } - title <- make_multiline_title(title) p <- p + - ggplot2::ggtitle(title) + - ggplot2::labs(colour = "Variable", linetype = "Version") + - ggplot2::theme_get() - - p <- add_facet_wrap( - p, - var = "group_var", scales = "free", - legend_labels = c( - unique(as.character(df_data$var)), - unique(df_data$version) - ) - ) - return(p) -} - -plot_dynamic_mixture_versions <- function(df_data, sit, successive, title = NULL) { - p <- ggplot2::ggplot( - df_data, - ggplot2::aes( - x = .data$Date, - colour = paste(.data$Dominance, ":", .data$Plant), - linetype = .data$version - ) - ) + - ggplot2::geom_line(ggplot2::aes(y = .data$Simulated)) + ggplot2::ggtitle(make_multiline_title(title)) + + ggplot2::theme_get() + + spec$extra - p <- add_vertical_lines(df_data, successive, p) + p <- add_facet_wrap(p, spec$facets, spec$scales, legend_labels = spec$legend_labels) - if ("Observed" %in% colnames(df_data)) { - p <- p + ggplot2::geom_point( - ggplot2::aes(y = .data$Observed), - na.rm = TRUE - ) - if ("Obs_SD" %in% colnames(df_data)) { - p <- p + - ggplot2::geom_errorbar( - ggplot2::aes( - ymin = .data$Observed - 2 * .data$Obs_SD, - ymax = .data$Observed + 2 * .data$Obs_SD - ), - na.rm = TRUE - ) - } - } - title <- make_multiline_title(title) - p <- p + - ggplot2::ggtitle(title) + - ggplot2::labs( - colour = "Plant", - linetype = "Version" - ) + - ggplot2::theme_get() - p <- add_facet_wrap( - p, - var = "var", scales = "free", - legend_labels = c( - unique(paste(df_data$Dominance, ":", df_data$Plant)), - unique(df_data$version) - ) - ) - return(p) + p } diff --git a/R/specific_plotting_scatter.R b/R/specific_plotting_scatter.R index 4756dc2..15c19ff 100644 --- a/R/specific_plotting_scatter.R +++ b/R/specific_plotting_scatter.R @@ -230,28 +230,24 @@ give_y_var_type <- function(select_scat) { #' @keywords internal -#' @description Add error bars on observed values in given scatterplot +#' @description Build a scatter plot shared by all the specific scatter plot +#' functions. #' @rdname specific_scatter_plots -#' @param p A ggplot to modify` -#' @param colour_factor The factor to use for colouring the error bars -#' @return The modified ggplot -add_obs_error_bars <- function(p, colour_factor = NULL) { - p <- p + - ggplot2::geom_linerange( - ggplot2::aes( - xmin = .data$Observed - 2 * .data$Obs_SD, - xmax = .data$Observed + 2 * .data$Obs_SD, - colour = .data[[colour_factor]], - ), - na.rm = TRUE - ) - return(p) -} - -#' @keywords internal -#' @rdname specific_scatter_plots -plot_scat_mixture_allsit <- function(df_data, sit, select_scat, shape_sit, - reference_var, is_obs_sd, title = NULL) { +#' @param mapping Aesthetic mapping of the points (colour and/or shape). When +#' `shape_sit` is "symbol" or "group", the situation is added on the shape, or +#' on the colour if `mapping` has no colour (it replaces any existing shape). +#' Error bars and text labels use the same colour as the points. +#' @param smooth_by_colour If TRUE, one regression line per point colour, +#' otherwise a single blue regression line. +#' @param extra List of additional ggplot components (labs, scales...). +#' @param legend_labels Named list (by aesthetic) of the labels displayed in the +#' legend, passed to `add_facet_wrap`. +#' @return A ggplot object +build_scatter_plot <- function( + df_data, select_scat, shape_sit, reference_var, is_obs_sd, title = NULL, + mapping = ggplot2::aes(), smooth_by_colour = FALSE, extra = NULL, + legend_labels = list() +) { tmp <- give_reference_var(reference_var) reference_var <- tmp$reference_var reference_var_name <- tmp$reference_var_name @@ -261,6 +257,20 @@ plot_scat_mixture_allsit <- function(df_data, sit, select_scat, shape_sit, df_data %>% dplyr::filter(!is.na(.data[[reference_var]]) & !is.na(.data[[y_var_type]])) + if (shape_sit %in% c("symbol", "group")) { + sit_aes <- if (is.null(mapping$colour)) "colour" else "shape" + mapping[[sit_aes]] <- rlang::quo(as.factor(.data$sit_name)) + extra <- c(extra, list(ggplot2::labs(!!sit_aes := "Situation"))) + legend_labels[[sit_aes]] <- unique(df_data$sit_name) + } + + smooth_aes <- ggplot2::aes(y = .data[[y_var_type]], x = .data[[reference_var]]) + smooth_params <- list(colour = "blue") + if (smooth_by_colour) { + smooth_aes$colour <- mapping$colour + smooth_params <- list() + } + p <- ggplot2::ggplot( df_data, @@ -268,68 +278,56 @@ plot_scat_mixture_allsit <- function(df_data, sit, select_scat, shape_sit, y = .data[[y_var_type]], x = .data[[reference_var]], label = .data$sit_name ) - ) - - if (shape_sit == "none" || shape_sit == "txt") { - p <- p + ggplot2::geom_point( - ggplot2::aes( - colour = as.factor(paste(.data$Dominance, ":", .data$Plant)) - ), - na.rm = TRUE - ) - } else if (shape_sit == "symbol" || shape_sit == "group") { - p <- p + ggplot2::geom_point( - ggplot2::aes( - colour = as.factor(paste(.data$Dominance, ":", .data$Plant)), - shape = as.factor(paste(.data$sit_name)) - ), - na.rm = TRUE ) + - ggplot2::scale_shape_discrete(name = "Situation") - } - - p <- p + + ggplot2::geom_point(mapping, na.rm = TRUE) + ggplot2::geom_abline( intercept = 0, slope = ifelse(select_scat == "sim", 1, 0), color = "grey30", linetype = 2 ) + - ggplot2::geom_smooth( - ggplot2::aes(y = .data[[y_var_type]], x = .data[[reference_var]]), - inherit.aes = FALSE, - method = lm, color = "blue", - se = FALSE, linewidth = 0.6, formula = y ~ x, - fullrange = TRUE, na.rm = TRUE + do.call( + ggplot2::geom_smooth, + c( + list( + mapping = smooth_aes, + inherit.aes = FALSE, + method = lm, + se = FALSE, linewidth = 0.6, formula = y ~ x, + fullrange = TRUE, na.rm = TRUE + ), + smooth_params + ) ) + - ggplot2::xlab(reference_var_name) - - p <- p + + ggplot2::xlab(reference_var_name) + ggplot2::ggtitle(title) if (is_obs_sd && reference_var == "Observed") { - p$data$colour_factor <- as.factor(paste(p$data$Dominance, ":", p$data$Plant)) - p <- add_obs_error_bars(p, colour_factor = "colour_factor") + error_aes <- ggplot2::aes( + xmin = .data$Observed - 2 * .data$Obs_SD, + xmax = .data$Observed + 2 * .data$Obs_SD + ) + error_aes$colour <- mapping$colour + p <- p + ggplot2::geom_linerange(error_aes, na.rm = TRUE) } p <- p + ggplot2::theme(aspect.ratio = 1) if (shape_sit == "txt") { + text_aes <- ggplot2::aes() + text_aes$colour <- mapping$colour p <- p + ggrepel::geom_text_repel( - ggplot2::aes( - colour = as.factor(paste(.data$Dominance, ":", .data$Plant)) - ), + text_aes, show.legend = FALSE, max.overlaps = 100 ) } + p <- p + extra + p <- add_facet_wrap( p, var = "var", scales = "free", - legend_labels = c( - unique(paste(df_data$Dominance, ":", df_data$Plant)), - if (shape_sit %in% c("symbol", "group")) unique(df_data$sit_name) - ) + legend_labels = unlist(legend_labels, use.names = FALSE) ) # Set same limits for x and y axis for sim VS obs scatter plots @@ -340,9 +338,23 @@ plot_scat_mixture_allsit <- function(df_data, sit, select_scat, shape_sit, p <- force_y_axis(df_data, reference_var, y_var_type, is_obs_sd, p) } - p <- p + ggplot2::scale_color_discrete(name = "Plant") + p +} - return(p) +#' @keywords internal +#' @rdname specific_scatter_plots +plot_scat_mixture_allsit <- function(df_data, sit, select_scat, shape_sit, + reference_var, is_obs_sd, title = NULL) { + build_scatter_plot( + df_data, select_scat, shape_sit, reference_var, is_obs_sd, title, + mapping = ggplot2::aes( + colour = as.factor(paste(.data$Dominance, ":", .data$Plant)) + ), + extra = list(ggplot2::labs(colour = "Plant")), + legend_labels = list( + colour = unique(paste(df_data$Dominance, ":", df_data$Plant)) + ) + ) } @@ -350,115 +362,24 @@ plot_scat_mixture_allsit <- function(df_data, sit, select_scat, shape_sit, #' @rdname specific_scatter_plots plot_scat_mixture_versions <- function(df_data, sit, select_scat, shape_sit, reference_var, is_obs_sd, title = NULL) { - tmp <- give_reference_var(reference_var) - reference_var <- tmp$reference_var - reference_var_name <- tmp$reference_var_name - y_var_type <- give_y_var_type(select_scat) - - df_data <- - df_data %>% - dplyr::filter(!is.na(.data[[reference_var]]) & !is.na(.data[[y_var_type]])) - - p <- - ggplot2::ggplot( - df_data, - ggplot2::aes( - y = .data[[y_var_type]], x = .data[[reference_var]], - label = .data$sit_name - ) - ) - - if (shape_sit == "none" || shape_sit == "txt") { - p <- p + ggplot2::geom_point( - ggplot2::aes( - shape = as.factor(paste(.data$Dominance, ":", .data$Plant)), - colour = as.factor(.data$version) - ), - na.rm = TRUE - ) + - ggplot2::labs(color = "Version", shape = "Plant") - } else if (shape_sit == "symbol" || shape_sit == "group") { - # ! In this case we loose the colour by species for mixtures, because - # there would be three aesthetics to handle (situation, version and - # species). We made this decision because the user explicitly asks - # for shape to be the situation name. If they want to color by species, + build_scatter_plot( + df_data, select_scat, shape_sit, reference_var, is_obs_sd, title, + # ! With shape_sit = "symbol" or "group", we loose the shape by species for + # mixtures, because there would be three aesthetics to handle (situation, + # version and species). We made this decision because the user explicitly + # asks for shape to be the situation name. If they want the species, # they can put shape_sit = "none" or shape_sit = "txt" to have it all. - p <- p + ggplot2::geom_point( - ggplot2::aes( - colour = as.factor(.data$version), - shape = as.factor(.data$sit_name) - ), - na.rm = TRUE - ) + - ggplot2::labs(color = "Version", shape = "Situation") - } - - p <- p + - ggplot2::geom_abline( - intercept = 0, slope = ifelse(select_scat == "sim", 1, 0), - color = "grey30", linetype = 2 - ) + - ggplot2::geom_smooth( - ggplot2::aes( - y = .data[[y_var_type]], x = .data[[reference_var]], - colour = as.factor(.data$version) - ), - inherit.aes = FALSE, - method = lm, - se = FALSE, linewidth = 0.6, formula = y ~ x, - fullrange = TRUE, na.rm = TRUE - ) + - ggplot2::xlab(reference_var_name) - - p <- p + ggplot2::ggtitle(title) - - if (is_obs_sd && reference_var == "Observed") { - p <- p + - ggplot2::geom_linerange( - ggplot2::aes( - xmin = .data$Observed - 2 * .data$Obs_SD, - xmax = .data$Observed + 2 * .data$Obs_SD, - colour = as.factor(.data$version), - ), - na.rm = TRUE - ) - } - - p <- p + ggplot2::theme(aspect.ratio = 1) - - if (shape_sit == "txt") { - p <- p + - ggrepel::geom_text_repel( - ggplot2::aes( - colour = as.factor(.data$version) - ), - show.legend = FALSE, - max.overlaps = 100 - ) - } - - p <- add_facet_wrap( - p, - var = "var", scales = "free", - legend_labels = c( - unique(df_data$version), - if (shape_sit %in% c("none", "txt")) { - unique(paste(df_data$Dominance, ":", df_data$Plant)) - } else { - unique(df_data$sit_name) - } + mapping = ggplot2::aes( + colour = as.factor(.data$version), + shape = as.factor(paste(.data$Dominance, ":", .data$Plant)) + ), + smooth_by_colour = TRUE, + extra = list(ggplot2::labs(colour = "Version", shape = "Plant")), + legend_labels = list( + colour = unique(df_data$version), + shape = unique(paste(df_data$Dominance, ":", df_data$Plant)) ) ) - - # Set same limits for x and y axis for sim VS obs scatter plots - if (select_scat == "sim" && reference_var == "Observed") { - p <- make_axis_square(df_data, reference_var, y_var_type, is_obs_sd, p) - } - if (select_scat == "res") { - p <- force_y_axis(df_data, reference_var, y_var_type, is_obs_sd, p) - } - - return(p) } @@ -468,88 +389,10 @@ plot_scat_allsit <- function(df_data, sit, select_scat, shape_sit, reference_var, is_obs_sd, title = NULL, has_distinct_situations = FALSE, one_version = FALSE, mixture = FALSE) { - tmp <- give_reference_var(reference_var) - reference_var <- tmp$reference_var - reference_var_name <- tmp$reference_var_name - y_var_type <- give_y_var_type(select_scat) - df_data <- - df_data %>% - dplyr::filter(!is.na(.data[[reference_var]]) & !is.na(.data[[y_var_type]])) - p <- - ggplot2::ggplot( - df_data, - ggplot2::aes( - y = .data[[y_var_type]], x = .data[[reference_var]], - label = .data$sit_name - ) - ) - if (shape_sit == "none" || shape_sit == "txt") { - p <- p + ggplot2::geom_point(na.rm = TRUE) - } else if (shape_sit == "symbol" || shape_sit == "group") { - p <- p + ggplot2::geom_point( - ggplot2::aes( - colour = as.factor(paste(.data$sit_name)) - ), - na.rm = TRUE - ) + - ggplot2::scale_color_discrete(name = "Situation") - } - - p <- p + - ggplot2::geom_abline( - intercept = 0, slope = ifelse(select_scat == "sim", 1, 0), - color = "grey30", linetype = 2 - ) + - ggplot2::geom_smooth( - ggplot2::aes(y = .data[[y_var_type]], x = .data[[reference_var]]), - inherit.aes = FALSE, - method = lm, color = "blue", - se = FALSE, linewidth = 0.6, formula = y ~ x, - fullrange = TRUE, na.rm = TRUE - ) + - ggplot2::xlab(reference_var_name) - - p <- p + - ggplot2::ggtitle(title) - - if (is_obs_sd && reference_var == "Observed") { - line_aes <- NULL - if (shape_sit == "symbol" || shape_sit == "group") { - line_aes <- ggplot2::aes( - xmin = .data$Observed - 2 * .data$Obs_SD, - xmax = .data$Observed + 2 * .data$Obs_SD, - colour = as.factor(paste(.data$sit_name)) - ) - } else { - line_aes <- ggplot2::aes( - xmin = .data$Observed - 2 * .data$Obs_SD, - xmax = .data$Observed + 2 * .data$Obs_SD - ) - } - p <- p + ggplot2::geom_linerange(line_aes, na.rm = TRUE) - } - - p <- p + ggplot2::theme(aspect.ratio = 1) - - if (shape_sit == "txt") { - p <- p + ggrepel::geom_text_repel(max.overlaps = 100) - } - - p <- add_facet_wrap( - p, - var = "var", scales = "free", - legend_labels = if (shape_sit %in% c("symbol", "group")) { - unique(df_data$sit_name) - } + p <- build_scatter_plot( + df_data, select_scat, shape_sit, reference_var, is_obs_sd, title ) - # Set same limits for x and y axis for sim VS obs scatter plots - if (select_scat == "sim" && reference_var == "Observed") { - p <- make_axis_square(df_data, reference_var, y_var_type, is_obs_sd, p) - } - if (select_scat == "res") { - p <- force_y_axis(df_data, reference_var, y_var_type, is_obs_sd, p) - } if ( has_distinct_situations == FALSE && one_version == TRUE && @@ -558,7 +401,7 @@ plot_scat_allsit <- function(df_data, sit, select_scat, shape_sit, p <- p + ggplot2::theme(legend.position = "none") } - return(p) + p } #' @keywords internal @@ -566,87 +409,16 @@ plot_scat_allsit <- function(df_data, sit, select_scat, shape_sit, plot_scat_versions_per_sit <- function(df_data, sit, select_scat, shape_sit, reference_var, is_obs_sd, title = NULL) { - tmp <- give_reference_var(reference_var) - reference_var <- tmp$reference_var - reference_var_name <- tmp$reference_var_name - y_var_type <- give_y_var_type(select_scat) - - df_data <- - df_data %>% - dplyr::filter(!is.na(.data[[reference_var]]) & !is.na(.data[[y_var_type]])) - - p <- - ggplot2::ggplot( - df_data, - ggplot2::aes( - y = .data[[y_var_type]], x = .data[[reference_var]], - label = .data$sit_name, - ) - ) - - p <- p + ggplot2::geom_point( - ggplot2::aes(colour = as.factor(.data$version)), - na.rm = TRUE - ) + - ggplot2::labs(color = "Version") - p <- p + - ggplot2::geom_abline( - intercept = 0, slope = ifelse(select_scat == "sim", 1, 0), - color = "grey30", linetype = 2 - ) + - ggplot2::geom_smooth( - ggplot2::aes( - y = .data[[y_var_type]], x = .data[[reference_var]], - colour = as.factor(.data$version) - ), - method = lm, - inherit.aes = FALSE, - se = FALSE, linewidth = 0.6, formula = y ~ x, - fullrange = TRUE, na.rm = TRUE - ) + - ggplot2::xlab(reference_var_name) - - p <- p + ggplot2::ggtitle(title) - if (shape_sit == "txt") { - p <- p + - ggrepel::geom_text_repel( - ggplot2::aes( - colour = as.factor(.data$version) - ), - show.legend = FALSE, - max.overlaps = 100 - ) - } - - if (is_obs_sd && reference_var == "Observed") { - p <- p + - ggplot2::geom_linerange( - ggplot2::aes( - xmin = .data$Observed - 2 * .data$Obs_SD, - xmax = .data$Observed + 2 * .data$Obs_SD, - colour = as.factor(.data$version), - ), - na.rm = TRUE - ) - } - - p <- p + ggplot2::theme(aspect.ratio = 1) - - p <- add_facet_wrap( - p, - var = "var", scales = "free", - legend_labels = unique(df_data$version) + build_scatter_plot( + df_data, select_scat, + # Only one situation per plot: no need for the situation in the legend + shape_sit = if (shape_sit == "txt") "txt" else "none", + reference_var, is_obs_sd, title, + mapping = ggplot2::aes(colour = as.factor(.data$version)), + smooth_by_colour = TRUE, + extra = list(ggplot2::labs(colour = "Version")), + legend_labels = list(colour = unique(df_data$version)) ) - - # Set same limits for x and y axis for sim VS obs scatter plots - if (select_scat == "sim" && reference_var == "Observed") { - p <- make_axis_square(df_data, reference_var, y_var_type, is_obs_sd, p) - } - if (select_scat == "res") { - p <- force_y_axis(df_data, reference_var, y_var_type, is_obs_sd, p) - } - - return(p) } @@ -655,106 +427,11 @@ plot_scat_versions_per_sit <- function(df_data, plot_scat_versions_allsit <- function(df_data, sit, select_scat, shape_sit, reference_var, is_obs_sd, title = NULL) { - tmp <- give_reference_var(reference_var) - reference_var <- tmp$reference_var - reference_var_name <- tmp$reference_var_name - y_var_type <- give_y_var_type(select_scat) - - df_data <- - df_data %>% - dplyr::filter(!is.na(.data[[reference_var]]) & !is.na(.data[[y_var_type]])) - - p <- - ggplot2::ggplot( - df_data, - ggplot2::aes( - y = .data[[y_var_type]], x = .data[[reference_var]], - label = .data$sit_name - ) - ) - - if (shape_sit == "none" || shape_sit == "txt") { - p <- p + ggplot2::geom_point( - ggplot2::aes( - colour = as.factor(.data$version) - ), - na.rm = TRUE - ) + - ggplot2::labs(color = "Version") - } else if (shape_sit == "symbol" || shape_sit == "group") { - # ! In this case we loose the colour by species for mixtures, because - # there would be three aesthetics to handle (situation, version and - # species). We made this decision because the user explicitly asks - # for shape to be the situation name. If they want to color by species, - # they can put shape_sit = "none" or shape_sit = "txt" to have it all. - p <- p + ggplot2::geom_point( - ggplot2::aes( - colour = as.factor(.data$version), - shape = as.factor(.data$sit_name) - ), - na.rm = TRUE - ) + - ggplot2::labs(color = "Version", shape = "Situation") - } - - p <- p + - ggplot2::geom_abline( - intercept = 0, slope = ifelse(select_scat == "sim", 1, 0), - color = "grey30", linetype = 2 - ) + - ggplot2::geom_smooth( - ggplot2::aes( - y = .data[[y_var_type]], x = .data[[reference_var]], - colour = as.factor(.data$version) - ), - inherit.aes = FALSE, - method = lm, - se = FALSE, linewidth = 0.6, formula = y ~ x, - fullrange = TRUE, na.rm = TRUE - ) + - ggplot2::xlab(reference_var_name) - - p <- p + ggplot2::ggtitle(title) - - if (is_obs_sd && reference_var == "Observed") { - p <- p + - ggplot2::geom_linerange( - ggplot2::aes( - xmin = .data$Observed - 2 * .data$Obs_SD, - xmax = .data$Observed + 2 * .data$Obs_SD, - colour = as.factor(.data$version), - ), - na.rm = TRUE - ) - } - - p <- p + ggplot2::theme(aspect.ratio = 1) - - if (shape_sit == "txt") { - p <- p + - ggrepel::geom_text_repel( - ggplot2::aes(colour = as.factor(.data$version)), - show.legend = FALSE, - max.overlaps = 100 - ) - } - - p <- add_facet_wrap( - p, - var = "var", scales = "free", - legend_labels = c( - unique(df_data$version), - if (shape_sit %in% c("symbol", "group")) unique(df_data$sit_name) - ) + build_scatter_plot( + df_data, select_scat, shape_sit, reference_var, is_obs_sd, title, + mapping = ggplot2::aes(colour = as.factor(.data$version)), + smooth_by_colour = TRUE, + extra = list(ggplot2::labs(colour = "Version")), + legend_labels = list(colour = unique(df_data$version)) ) - - # Set same limits for x and y axis for sim VS obs scatter plots - if (select_scat == "sim" && reference_var == "Observed") { - p <- make_axis_square(df_data, reference_var, y_var_type, is_obs_sd, p) - } - if (select_scat == "res") { - p <- force_y_axis(df_data, reference_var, y_var_type, is_obs_sd, p) - } - - return(p) } diff --git a/man/specific_dynamic_plots.Rd b/man/specific_dynamic_plots.Rd index 28b1ea9..a00c4bb 100644 --- a/man/specific_dynamic_plots.Rd +++ b/man/specific_dynamic_plots.Rd @@ -4,14 +4,11 @@ \alias{specific_dynamic_plots} \alias{add_vertical_lines} \alias{make_multiline_title} -\alias{plot_dynamic} \title{Specific functions to generate dynamic plots} \usage{ add_vertical_lines(df_data, successive, p) make_multiline_title(title, max_char = 120) - -plot_dynamic(df_data, sit, successive, title = NULL) } \arguments{ \item{df_data}{A named list of data frame including the data to plot (one df diff --git a/man/specific_scatter_plots.Rd b/man/specific_scatter_plots.Rd index 405ccf4..0cccab8 100644 --- a/man/specific_scatter_plots.Rd +++ b/man/specific_scatter_plots.Rd @@ -6,7 +6,7 @@ \alias{compute_axis_bounds} \alias{make_axis_square} \alias{force_y_axis} -\alias{add_obs_error_bars} +\alias{build_scatter_plot} \alias{plot_scat_mixture_allsit} \alias{plot_scat_mixture_versions} \alias{plot_scat_allsit} @@ -22,7 +22,18 @@ make_axis_square(df_data, reference_var, y_var_type, is_obs_sd, p) force_y_axis(df_data, reference_var, y_var_type, is_obs_sd, p) -add_obs_error_bars(p, colour_factor = NULL) +build_scatter_plot( + df_data, + select_scat, + shape_sit, + reference_var, + is_obs_sd, + title = NULL, + mapping = ggplot2::aes(), + smooth_by_colour = FALSE, + extra = NULL, + legend_labels = list() +) plot_scat_mixture_allsit( df_data, @@ -90,7 +101,18 @@ per situation, or only one df if sit==all_situations)} \item{is_obs_sd}{TRUE if error standard deviation of observations is provided} -\item{colour_factor}{The factor to use for colouring the error bars} +\item{mapping}{Aesthetic mapping of the points (colour and/or shape). When +\code{shape_sit} is "symbol" or "group", the situation is added on the shape, or +on the colour if \code{mapping} has no colour (it replaces any existing shape). +Error bars and text labels use the same colour as the points.} + +\item{smooth_by_colour}{If TRUE, one regression line per point colour, +otherwise a single blue regression line.} + +\item{extra}{List of additional ggplot components (labs, scales...).} + +\item{legend_labels}{Named list (by aesthetic) of the labels displayed in the +legend, passed to \code{add_facet_wrap}.} \item{sit}{The name of the situation to plot (or all_situations)} @@ -114,7 +136,7 @@ The modified ggplot The modified ggplot -The modified ggplot +A ggplot object } \description{ Generate scatter plots for the different cases handled in @@ -135,7 +157,8 @@ Make axis square Ensure that the Y axis includes zero when all values in a facet are strictly positive or strictly negative. -Add error bars on observed values in given scatterplot +Build a scatter plot shared by all the specific scatter plot +functions. } \details{ List of the different specific functions: From 7c7a315a3f4ca1092904c29c1f5c6557e6b897fc Mon Sep 17 00:00:00 2001 From: vrahier Date: Wed, 7 Oct 2026 12:40:33 +0000 Subject: [PATCH 2/6] Style code (GHA) --- R/generic_plotting.R | 78 +++++++++++++++++------------------ R/specific_plotting_dynamic.R | 5 +-- 2 files changed, 41 insertions(+), 42 deletions(-) diff --git a/R/generic_plotting.R b/R/generic_plotting.R index 0c70891..b0d40ca 100644 --- a/R/generic_plotting.R +++ b/R/generic_plotting.R @@ -191,46 +191,46 @@ plot_situations <- function(..., obs = NULL, obs_sd = NULL, ) } else { p[[i]] <- switch(item_case, - # 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 - ) + # 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 ) + ) } } diff --git a/R/specific_plotting_dynamic.R b/R/specific_plotting_dynamic.R index 377239f..104bfa7 100644 --- a/R/specific_plotting_dynamic.R +++ b/R/specific_plotting_dynamic.R @@ -102,8 +102,7 @@ dynamic_plot_spec <- function(df_data, mixture, one_version, overlap) { sep = "_" ) - switch( - spec_name, + switch(spec_name, mixture_one_version_no_overlap = list( mapping = ggplot2::aes(colour = paste(.data$Dominance, ":", .data$Plant)), scales = "free_y", facets = "var", @@ -201,7 +200,7 @@ dynamic_plot_spec <- function(df_data, mixture, one_version, overlap) { build_dynamic_plot <- function(df_data, sit, successive, title = NULL, mixture, one_version, overlap) { - spec <- dynamic_plot_spec(df_data,mixture, one_version, overlap) + spec <- dynamic_plot_spec(df_data, mixture, one_version, overlap) p <- ggplot2::ggplot( df_data, ggplot2::aes(x = .data$Date, !!!spec$mapping) From bd63d80f7a4156a69091f26aaa2af824e9a5e2a6 Mon Sep 17 00:00:00 2001 From: Valentine Rahier Date: Wed, 7 Oct 2026 14:58:45 +0200 Subject: [PATCH 3/6] fix scales --- R/specific_plotting_dynamic.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/specific_plotting_dynamic.R b/R/specific_plotting_dynamic.R index 104bfa7..4c7ae6f 100644 --- a/R/specific_plotting_dynamic.R +++ b/R/specific_plotting_dynamic.R @@ -237,7 +237,8 @@ build_dynamic_plot <- function(df_data, sit, successive, title = NULL, ggplot2::theme_get() + spec$extra - p <- add_facet_wrap(p, spec$facets, spec$scales, legend_labels = spec$legend_labels) + scales <- if (is.null(spec$scales)) "free" else spec$scales + p <- add_facet_wrap(p, spec$facets, scales, legend_labels = spec$legend_labels) p } From 02ad3be584c7413d53ba28f758cefc061e17dcc8 Mon Sep 17 00:00:00 2001 From: Valentine Rahier Date: Wed, 7 Oct 2026 15:19:22 +0200 Subject: [PATCH 4/6] clean code --- R/aesthetics.R | 29 ----- R/generic_plotting.R | 48 +------- R/specific_plotting_scatter.R | 204 ++++++++++++++-------------------- man/detect_item_case.Rd | 36 ------ man/specific_scatter_plots.Rd | 109 +++++------------- 5 files changed, 114 insertions(+), 312 deletions(-) delete mode 100644 man/detect_item_case.Rd diff --git a/R/aesthetics.R b/R/aesthetics.R index 5b0a0d4..8c30066 100644 --- a/R/aesthetics.R +++ b/R/aesthetics.R @@ -89,32 +89,3 @@ detect_mixture_version_situations <- function(is_mixture, one_version, has_disti 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) -} diff --git a/R/generic_plotting.R b/R/generic_plotting.R index b0d40ca..c6b47be 100644 --- a/R/generic_plotting.R +++ b/R/generic_plotting.R @@ -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]] @@ -190,46 +187,11 @@ plot_situations <- function(..., obs = NULL, obs_sd = NULL, mixture, one_version, overlap ) } else { - p[[i]] <- switch(item_case, - # 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 - ) + 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 ) } } diff --git a/R/specific_plotting_scatter.R b/R/specific_plotting_scatter.R index 15c19ff..fa83919 100644 --- a/R/specific_plotting_scatter.R +++ b/R/specific_plotting_scatter.R @@ -17,10 +17,9 @@ #' #' @details List of the different specific functions: #' \itemize{ -#' \item `plot_scat_mixture_allsit`: Generate a scatter plot for the case of -#' mixture of crops, single simulation version and all_situations in same plot -#' \item `plot_scat_allsit`: Generate a scatter plot for the case of -#' sole crops, single simulation version and all_situations in same plot +#' \item `scatter_plot_spec`: Give the aesthetics, labels and legend of the +#' scatter plot according to the case (mixture or not, one or several versions) +#' \item `build_scatter_plot`: Generate a scatter plot for all the cases #' } #' #' @return A list of ggplot objects @@ -228,25 +227,68 @@ give_y_var_type <- function(select_scat) { return(y_var_type) } +#' @keywords internal +#' @description Give the plot specification (aesthetics, labels, legend) of a +#' scatter plot according to the case: mixture or not, one or several versions. +#' @rdname specific_scatter_plots +#' @return A list with `mapping` (aesthetic mapping of the points), +#' `smooth_by_colour` (one regression line per point colour if TRUE, otherwise +#' a single blue line), `extra` (additional ggplot components) and +#' `legend_labels` (named list by aesthetic of the legend labels). +scatter_plot_spec <- function(df_data, mixture, one_version) { + plant_labels <- unique(paste(df_data$Dominance, ":", df_data$Plant)) + + if (mixture && one_version) { + list( + mapping = ggplot2::aes( + colour = as.factor(paste(.data$Dominance, ":", .data$Plant)) + ), + smooth_by_colour = FALSE, + extra = list(ggplot2::labs(colour = "Plant")), + legend_labels = list(colour = plant_labels) + ) + } else if (mixture) { + list( + mapping = ggplot2::aes( + colour = as.factor(.data$version), + shape = as.factor(paste(.data$Dominance, ":", .data$Plant)) + ), + smooth_by_colour = TRUE, + extra = list(ggplot2::labs(colour = "Version", shape = "Plant")), + legend_labels = list( + colour = unique(df_data$version), + shape = plant_labels + ) + ) + } else if (!one_version) { + list( + mapping = ggplot2::aes(colour = as.factor(.data$version)), + smooth_by_colour = TRUE, + extra = list(ggplot2::labs(colour = "Version")), + legend_labels = list(colour = unique(df_data$version)) + ) + } else { + list( + mapping = ggplot2::aes(), + smooth_by_colour = FALSE, + extra = NULL, + legend_labels = list() + ) + } +} + #' @keywords internal -#' @description Build a scatter plot shared by all the specific scatter plot -#' functions. +#' @description Build a scatter plot for all the cases handled in CroPlotR. +#' When `shape_sit` is "symbol" or "group", the situation is added on the +#' shape of the points, or on their colour if no colour is used (it replaces +#' any existing shape). Error bars and text labels use the same colour as the +#' points. #' @rdname specific_scatter_plots -#' @param mapping Aesthetic mapping of the points (colour and/or shape). When -#' `shape_sit` is "symbol" or "group", the situation is added on the shape, or -#' on the colour if `mapping` has no colour (it replaces any existing shape). -#' Error bars and text labels use the same colour as the points. -#' @param smooth_by_colour If TRUE, one regression line per point colour, -#' otherwise a single blue regression line. -#' @param extra List of additional ggplot components (labs, scales...). -#' @param legend_labels Named list (by aesthetic) of the labels displayed in the -#' legend, passed to `add_facet_wrap`. #' @return A ggplot object build_scatter_plot <- function( df_data, select_scat, shape_sit, reference_var, is_obs_sd, title = NULL, - mapping = ggplot2::aes(), smooth_by_colour = FALSE, extra = NULL, - legend_labels = list() + mixture = FALSE, one_version = TRUE, has_distinct_situations = FALSE ) { tmp <- give_reference_var(reference_var) reference_var <- tmp$reference_var @@ -257,17 +299,30 @@ build_scatter_plot <- function( df_data %>% dplyr::filter(!is.na(.data[[reference_var]]) & !is.na(.data[[y_var_type]])) + spec <- scatter_plot_spec(df_data, mixture, one_version) + + # Sole crop, versions, one situation per plot: no need for the situation in + # the legend + if (!mixture && !one_version && !has_distinct_situations) { + shape_sit <- if (shape_sit == "txt") "txt" else "none" + } + if (shape_sit %in% c("symbol", "group")) { - sit_aes <- if (is.null(mapping$colour)) "colour" else "shape" - mapping[[sit_aes]] <- rlang::quo(as.factor(.data$sit_name)) - extra <- c(extra, list(ggplot2::labs(!!sit_aes := "Situation"))) - legend_labels[[sit_aes]] <- unique(df_data$sit_name) + # ! For mixtures with versions, the situation replaces the species on the + # shape, because there would be three aesthetics to handle (situation, + # version and species). We made this decision because the user explicitly + # asks for shape to be the situation name. If they want the species, + # they can put shape_sit = "none" or shape_sit = "txt" to have it all. + sit_aes <- if (is.null(spec$mapping$colour)) "colour" else "shape" + spec$mapping[[sit_aes]] <- rlang::quo(as.factor(.data$sit_name)) + spec$extra <- c(spec$extra, list(ggplot2::labs(!!sit_aes := "Situation"))) + spec$legend_labels[[sit_aes]] <- unique(df_data$sit_name) } smooth_aes <- ggplot2::aes(y = .data[[y_var_type]], x = .data[[reference_var]]) smooth_params <- list(colour = "blue") - if (smooth_by_colour) { - smooth_aes$colour <- mapping$colour + if (spec$smooth_by_colour) { + smooth_aes$colour <- spec$mapping$colour smooth_params <- list() } @@ -279,7 +334,7 @@ build_scatter_plot <- function( label = .data$sit_name ) ) + - ggplot2::geom_point(mapping, na.rm = TRUE) + + ggplot2::geom_point(spec$mapping, na.rm = TRUE) + ggplot2::geom_abline( intercept = 0, slope = ifelse(select_scat == "sim", 1, 0), color = "grey30", linetype = 2 @@ -305,7 +360,7 @@ build_scatter_plot <- function( xmin = .data$Observed - 2 * .data$Obs_SD, xmax = .data$Observed + 2 * .data$Obs_SD ) - error_aes$colour <- mapping$colour + error_aes$colour <- spec$mapping$colour p <- p + ggplot2::geom_linerange(error_aes, na.rm = TRUE) } @@ -313,7 +368,7 @@ build_scatter_plot <- function( if (shape_sit == "txt") { text_aes <- ggplot2::aes() - text_aes$colour <- mapping$colour + text_aes$colour <- spec$mapping$colour p <- p + ggrepel::geom_text_repel( text_aes, @@ -322,12 +377,12 @@ build_scatter_plot <- function( ) } - p <- p + extra + p <- p + spec$extra p <- add_facet_wrap( p, var = "var", scales = "free", - legend_labels = unlist(legend_labels, use.names = FALSE) + legend_labels = unlist(spec$legend_labels, use.names = FALSE) ) # Set same limits for x and y axis for sim VS obs scatter plots @@ -338,100 +393,9 @@ build_scatter_plot <- function( p <- force_y_axis(df_data, reference_var, y_var_type, is_obs_sd, p) } - p -} - -#' @keywords internal -#' @rdname specific_scatter_plots -plot_scat_mixture_allsit <- function(df_data, sit, select_scat, shape_sit, - reference_var, is_obs_sd, title = NULL) { - build_scatter_plot( - df_data, select_scat, shape_sit, reference_var, is_obs_sd, title, - mapping = ggplot2::aes( - colour = as.factor(paste(.data$Dominance, ":", .data$Plant)) - ), - extra = list(ggplot2::labs(colour = "Plant")), - legend_labels = list( - colour = unique(paste(df_data$Dominance, ":", df_data$Plant)) - ) - ) -} - - -#' @keywords internal -#' @rdname specific_scatter_plots -plot_scat_mixture_versions <- function(df_data, sit, select_scat, shape_sit, - reference_var, is_obs_sd, title = NULL) { - build_scatter_plot( - df_data, select_scat, shape_sit, reference_var, is_obs_sd, title, - # ! With shape_sit = "symbol" or "group", we loose the shape by species for - # mixtures, because there would be three aesthetics to handle (situation, - # version and species). We made this decision because the user explicitly - # asks for shape to be the situation name. If they want the species, - # they can put shape_sit = "none" or shape_sit = "txt" to have it all. - mapping = ggplot2::aes( - colour = as.factor(.data$version), - shape = as.factor(paste(.data$Dominance, ":", .data$Plant)) - ), - smooth_by_colour = TRUE, - extra = list(ggplot2::labs(colour = "Version", shape = "Plant")), - legend_labels = list( - colour = unique(df_data$version), - shape = unique(paste(df_data$Dominance, ":", df_data$Plant)) - ) - ) -} - - -#' @keywords internal -#' @rdname specific_scatter_plots -plot_scat_allsit <- function(df_data, sit, select_scat, shape_sit, - reference_var, is_obs_sd, title = NULL, - has_distinct_situations = FALSE, - one_version = FALSE, mixture = FALSE) { - p <- build_scatter_plot( - df_data, select_scat, shape_sit, reference_var, is_obs_sd, title - ) - - if ( - has_distinct_situations == FALSE && - one_version == TRUE && - mixture == FALSE - ) { + if (!has_distinct_situations && one_version && !mixture) { p <- p + ggplot2::theme(legend.position = "none") } p } - -#' @keywords internal -#' @rdname specific_scatter_plots -plot_scat_versions_per_sit <- function(df_data, - sit, select_scat, shape_sit, - reference_var, is_obs_sd, title = NULL) { - build_scatter_plot( - df_data, select_scat, - # Only one situation per plot: no need for the situation in the legend - shape_sit = if (shape_sit == "txt") "txt" else "none", - reference_var, is_obs_sd, title, - mapping = ggplot2::aes(colour = as.factor(.data$version)), - smooth_by_colour = TRUE, - extra = list(ggplot2::labs(colour = "Version")), - legend_labels = list(colour = unique(df_data$version)) - ) -} - - -#' @keywords internal -#' @rdname specific_scatter_plots -plot_scat_versions_allsit <- function(df_data, - sit, select_scat, shape_sit, - reference_var, is_obs_sd, title = NULL) { - build_scatter_plot( - df_data, select_scat, shape_sit, reference_var, is_obs_sd, title, - mapping = ggplot2::aes(colour = as.factor(.data$version)), - smooth_by_colour = TRUE, - extra = list(ggplot2::labs(colour = "Version")), - legend_labels = list(colour = unique(df_data$version)) - ) -} diff --git a/man/detect_item_case.Rd b/man/detect_item_case.Rd deleted file mode 100644 index cefa32c..0000000 --- a/man/detect_item_case.Rd +++ /dev/null @@ -1,36 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/aesthetics.R -\name{detect_item_case} -\alias{detect_item_case} -\title{Detect items cases} -\usage{ -detect_item_case( - type, - is_mixture, - one_version, - has_distinct_situations, - overlap -) -} -\arguments{ -\item{type}{The type of plot required, either 'dynamic' or 'scatter} - -\item{is_mixture}{A logical value indicating whether the crop is a mixture or not.} - -\item{one_version}{A logical value indicating whether the plot has one or multiple versions (e.g. of the model).} - -\item{has_distinct_situations}{A logical value indicating whether there are one or several situations to plot.} - -\item{overlap}{A logical value indicating whether there is any overlapping variables in the plot.} -} -\value{ -A unique character string for the plot. -} -\description{ -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. -} -\keyword{internal} diff --git a/man/specific_scatter_plots.Rd b/man/specific_scatter_plots.Rd index 0cccab8..4873845 100644 --- a/man/specific_scatter_plots.Rd +++ b/man/specific_scatter_plots.Rd @@ -6,12 +6,8 @@ \alias{compute_axis_bounds} \alias{make_axis_square} \alias{force_y_axis} +\alias{scatter_plot_spec} \alias{build_scatter_plot} -\alias{plot_scat_mixture_allsit} -\alias{plot_scat_mixture_versions} -\alias{plot_scat_allsit} -\alias{plot_scat_versions_per_sit} -\alias{plot_scat_versions_allsit} \title{Specific functions to generate scatter plots} \usage{ get_facet_order(p, facet_var = "var") @@ -22,70 +18,18 @@ make_axis_square(df_data, reference_var, y_var_type, is_obs_sd, p) force_y_axis(df_data, reference_var, y_var_type, is_obs_sd, p) -build_scatter_plot( - df_data, - select_scat, - shape_sit, - reference_var, - is_obs_sd, - title = NULL, - mapping = ggplot2::aes(), - smooth_by_colour = FALSE, - extra = NULL, - legend_labels = list() -) +scatter_plot_spec(df_data, mixture, one_version) -plot_scat_mixture_allsit( - df_data, - sit, - select_scat, - shape_sit, - reference_var, - is_obs_sd, - title = NULL -) - -plot_scat_mixture_versions( - df_data, - sit, - select_scat, - shape_sit, - reference_var, - is_obs_sd, - title = NULL -) - -plot_scat_allsit( +build_scatter_plot( df_data, - sit, select_scat, shape_sit, reference_var, is_obs_sd, title = NULL, - has_distinct_situations = FALSE, - one_version = FALSE, - mixture = FALSE -) - -plot_scat_versions_per_sit( - df_data, - sit, - select_scat, - shape_sit, - reference_var, - is_obs_sd, - title = NULL -) - -plot_scat_versions_allsit( - df_data, - sit, - select_scat, - shape_sit, - reference_var, - is_obs_sd, - title = NULL + mixture = FALSE, + one_version = TRUE, + has_distinct_situations = FALSE ) } \arguments{ @@ -101,26 +45,13 @@ per situation, or only one df if sit==all_situations)} \item{is_obs_sd}{TRUE if error standard deviation of observations is provided} -\item{mapping}{Aesthetic mapping of the points (colour and/or shape). When -\code{shape_sit} is "symbol" or "group", the situation is added on the shape, or -on the colour if \code{mapping} has no colour (it replaces any existing shape). -Error bars and text labels use the same colour as the points.} - -\item{smooth_by_colour}{If TRUE, one regression line per point colour, -otherwise a single blue regression line.} - -\item{extra}{List of additional ggplot components (labs, scales...).} - -\item{legend_labels}{Named list (by aesthetic) of the labels displayed in the -legend, passed to \code{add_facet_wrap}.} +\item{mixture}{TRUE if the plot is for a mixture of crops} -\item{sit}{The name of the situation to plot (or all_situations)} +\item{one_version}{TRUE if the plot is for one version} \item{has_distinct_situations}{TRUE if the plot is for several situations} -\item{one_version}{TRUE if the plot is for one version} - -\item{mixture}{TRUE if the plot is for a mixture of crops} +\item{sit}{The name of the situation to plot (or all_situations)} } \value{ A ggplot object @@ -136,6 +67,11 @@ The modified ggplot The modified ggplot +A list with \code{mapping} (aesthetic mapping of the points), +\code{smooth_by_colour} (one regression line per point colour if TRUE, otherwise +a single blue line), \code{extra} (additional ggplot components) and +\code{legend_labels} (named list by aesthetic of the legend labels). + A ggplot object } \description{ @@ -157,16 +93,21 @@ Make axis square Ensure that the Y axis includes zero when all values in a facet are strictly positive or strictly negative. -Build a scatter plot shared by all the specific scatter plot -functions. +Give the plot specification (aesthetics, labels, legend) of a +scatter plot according to the case: mixture or not, one or several versions. + +Build a scatter plot for all the cases handled in CroPlotR. +When \code{shape_sit} is "symbol" or "group", the situation is added on the +shape of the points, or on their colour if no colour is used (it replaces +any existing shape). Error bars and text labels use the same colour as the +points. } \details{ List of the different specific functions: \itemize{ -\item \code{plot_scat_mixture_allsit}: Generate a scatter plot for the case of -mixture of crops, single simulation version and all_situations in same plot -\item \code{plot_scat_allsit}: Generate a scatter plot for the case of -sole crops, single simulation version and all_situations in same plot +\item \code{scatter_plot_spec}: Give the aesthetics, labels and legend of the +scatter plot according to the case (mixture or not, one or several versions) +\item \code{build_scatter_plot}: Generate a scatter plot for all the cases } The function relies on \code{ggplot2::ggplot_build()} to compute the plot From 36285e38faecaf2aff10023ecab40fa7ad477f74 Mon Sep 17 00:00:00 2001 From: Valentine Rahier Date: Wed, 7 Oct 2026 15:56:48 +0200 Subject: [PATCH 5/6] remove dead code --- R/aesthetics.R | 55 ------------------------ man/detect_mixture_version_overlap.Rd | 24 ----------- man/detect_mixture_version_situations.Rd | 28 ------------ 3 files changed, 107 deletions(-) delete mode 100644 man/detect_mixture_version_overlap.Rd delete mode 100644 man/detect_mixture_version_situations.Rd diff --git a/R/aesthetics.R b/R/aesthetics.R index 8c30066..e5b6280 100644 --- a/R/aesthetics.R +++ b/R/aesthetics.R @@ -34,58 +34,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) -} diff --git a/man/detect_mixture_version_overlap.Rd b/man/detect_mixture_version_overlap.Rd deleted file mode 100644 index de6c8be..0000000 --- a/man/detect_mixture_version_overlap.Rd +++ /dev/null @@ -1,24 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/aesthetics.R -\name{detect_mixture_version_overlap} -\alias{detect_mixture_version_overlap} -\title{Detect items cases for dynamic plots} -\usage{ -detect_mixture_version_overlap(is_mixture, one_version, overlap) -} -\arguments{ -\item{is_mixture}{A logical value indicating whether the crop is a mixture or not.} - -\item{one_version}{A logical value indicating whether the plot has one or multiple versions (e.g. of the model).} - -\item{overlap}{A logical value indicating whether there is any overlapping variables in the plot.} -} -\value{ -A character string indicating the case for computing the aesthetics of the plot. -} -\description{ -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. -} -\keyword{internal} diff --git a/man/detect_mixture_version_situations.Rd b/man/detect_mixture_version_situations.Rd deleted file mode 100644 index fe342d6..0000000 --- a/man/detect_mixture_version_situations.Rd +++ /dev/null @@ -1,28 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/aesthetics.R -\name{detect_mixture_version_situations} -\alias{detect_mixture_version_situations} -\title{Detect items cases for scatter plots} -\usage{ -detect_mixture_version_situations( - is_mixture, - one_version, - has_distinct_situations -) -} -\arguments{ -\item{is_mixture}{A logical value indicating whether the crop is a mixture or not.} - -\item{one_version}{A logical value indicating whether the plot has one or multiple versions (e.g. of the model).} - -\item{has_distinct_situations}{A logical value indicating whether there are one or several situations to plot.} -} -\value{ -A character string indicating the case for computing the aesthetics of the plot. -} -\description{ -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. -} -\keyword{internal} From 1935eb932cbbfe8ad8178e389742e6f1f63b82ec Mon Sep 17 00:00:00 2001 From: vrahier Date: Wed, 7 Oct 2026 13:58:12 +0000 Subject: [PATCH 6/6] Style code (GHA) --- R/aesthetics.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/aesthetics.R b/R/aesthetics.R index e5b6280..55e4ef0 100644 --- a/R/aesthetics.R +++ b/R/aesthetics.R @@ -33,4 +33,3 @@ detect_mixture <- function(sim_situation) { return(is_mixture) } -