diff --git a/R/aesthetics.R b/R/aesthetics.R index 5b0a0d4..55e4ef0 100644 --- a/R/aesthetics.R +++ b/R/aesthetics.R @@ -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) -} diff --git a/R/generic_plotting.R b/R/generic_plotting.R index 006e954..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]] @@ -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 diff --git a/R/specific_plotting_dynamic.R b/R/specific_plotting_dynamic.R index 8fae437..4c7ae6f 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) + scales <- if (is.null(spec$scales)) "free" else spec$scales + p <- add_facet_wrap(p, spec$facets, 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..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,128 +227,69 @@ give_y_var_type <- function(select_scat) { return(y_var_type) } - #' @keywords internal -#' @description Add error bars on observed values in given scatterplot +#' @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 -#' @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) { - 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( +#' @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)) ), - na.rm = TRUE + smooth_by_colour = FALSE, + extra = list(ggplot2::labs(colour = "Plant")), + legend_labels = list(colour = plant_labels) ) - } 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)) + } else if (mixture) { + list( + mapping = ggplot2::aes( + colour = as.factor(.data$version), + shape = as.factor(paste(.data$Dominance, ":", .data$Plant)) ), - na.rm = TRUE - ) + - ggplot2::scale_shape_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") { - p$data$colour_factor <- as.factor(paste(p$data$Dominance, ":", p$data$Plant)) - p <- add_obs_error_bars(p, colour_factor = "colour_factor") - } - - p <- p + ggplot2::theme(aspect.ratio = 1) - - if (shape_sit == "txt") { - p <- p + - ggrepel::geom_text_repel( - ggplot2::aes( - colour = as.factor(paste(.data$Dominance, ":", .data$Plant)) - ), - show.legend = FALSE, - max.overlaps = 100 + smooth_by_colour = TRUE, + extra = list(ggplot2::labs(colour = "Version", shape = "Plant")), + legend_labels = list( + colour = unique(df_data$version), + shape = plant_labels ) - } - - 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) ) - ) - - # 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) + } 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() + ) } - - p <- p + ggplot2::scale_color_discrete(name = "Plant") - - return(p) } #' @keywords internal +#' @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 -plot_scat_mixture_versions <- function(df_data, sit, select_scat, shape_sit, - reference_var, is_obs_sd, title = NULL) { +#' @return A ggplot object +build_scatter_plot <- function( + df_data, select_scat, shape_sit, reference_var, is_obs_sd, title = NULL, + mixture = FALSE, one_version = TRUE, has_distinct_situations = FALSE +) { tmp <- give_reference_var(reference_var) reference_var <- tmp$reference_var reference_var_name <- tmp$reference_var_name @@ -359,122 +299,33 @@ plot_scat_mixture_versions <- function(df_data, sit, select_scat, shape_sit, 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 - ) - ) + spec <- scatter_plot_spec(df_data, mixture, one_version) - 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, - # 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 - ) + # 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" } - 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 - ) + if (shape_sit %in% c("symbol", "group")) { + # ! 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) } - 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) - } - ) - ) - - # 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) + smooth_aes <- ggplot2::aes(y = .data[[y_var_type]], x = .data[[reference_var]]) + smooth_params <- list(colour = "blue") + if (spec$smooth_by_colour) { + smooth_aes$colour <- spec$mapping$colour + smooth_params <- list() } - if (select_scat == "res") { - p <- force_y_axis(df_data, reference_var, y_var_type, is_obs_sd, p) - } - - return(p) -} - -#' @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) { - 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, @@ -482,160 +333,56 @@ plot_scat_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(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_point(spec$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") { - 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) + error_aes <- ggplot2::aes( + xmin = .data$Observed - 2 * .data$Obs_SD, + xmax = .data$Observed + 2 * .data$Obs_SD + ) + error_aes$colour <- spec$mapping$colour + p <- p + ggplot2::geom_linerange(error_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) - } - ) - - # 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 && - mixture == FALSE - ) { - p <- p + ggplot2::theme(legend.position = "none") - } - - return(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) { - 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") { + text_aes <- ggplot2::aes() + text_aes$colour <- spec$mapping$colour p <- p + ggrepel::geom_text_repel( - ggplot2::aes( - colour = as.factor(.data$version) - ), + text_aes, 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 <- p + spec$extra p <- add_facet_wrap( p, var = "var", scales = "free", - legend_labels = unique(df_data$version) + legend_labels = unlist(spec$legend_labels, use.names = FALSE) ) # Set same limits for x and y axis for sim VS obs scatter plots @@ -646,115 +393,9 @@ plot_scat_versions_per_sit <- function(df_data, p <- force_y_axis(df_data, reference_var, y_var_type, is_obs_sd, p) } - return(p) -} - - -#' @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) { - 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) - ) - ) - - # 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 && one_version && !mixture) { + p <- p + ggplot2::theme(legend.position = "none") } - return(p) + p } 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/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} 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..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{add_obs_error_bars} -\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} +\alias{scatter_plot_spec} +\alias{build_scatter_plot} \title{Specific functions to generate scatter plots} \usage{ get_facet_order(p, facet_var = "var") @@ -22,59 +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) -add_obs_error_bars(p, colour_factor = NULL) +scatter_plot_spec(df_data, mixture, one_version) -plot_scat_mixture_allsit( +build_scatter_plot( 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( - 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{ @@ -90,15 +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{colour_factor}{The factor to use for colouring the error bars} +\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 @@ -114,7 +67,12 @@ The modified ggplot 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{ Generate scatter plots for the different cases handled in @@ -135,15 +93,21 @@ 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 +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