From 9f48a5b2ebbf023e4a7e608043cff316f5cd5b48 Mon Sep 17 00:00:00 2001 From: himmil Date: Thu, 19 Oct 2023 10:35:28 +0300 Subject: [PATCH] fix aes_string --- NAMESPACE | 1 + R/plotGraph.R | 2 +- R/utils_plotting.R | 46 ++++++++++++++++++++++++++-------------------- man/plotCCA.Rd | 2 +- 4 files changed, 29 insertions(+), 22 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 768d624d..a22eb005 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -127,6 +127,7 @@ importFrom(tidygraph,as_tibble) importFrom(tidyr,drop_na) importFrom(tidyr,nest) importFrom(tidyr,pivot_longer) +importFrom(tidyr,tags) importFrom(tidyr,unnest) importFrom(tidytree,as.phylo) importFrom(tidytree,as.treedata) diff --git a/R/plotGraph.R b/R/plotGraph.R index b2836b0d..bc844eeb 100644 --- a/R/plotGraph.R +++ b/R/plotGraph.R @@ -642,7 +642,7 @@ setMethod("plotRowGraph", plot_out } -#' @importFrom tidyr drop_na +#' @importFrom tidyr drop_na tags .add_graph_labels <- function(plot_out, show_label){ if(show_label){ label_data <- plot_out$data %>% drop_na(label) diff --git a/R/utils_plotting.R b/R/utils_plotting.R index 58ef0dd4..73539c68 100644 --- a/R/utils_plotting.R +++ b/R/utils_plotting.R @@ -255,18 +255,19 @@ NULL { fill_colour <- TRUE border <- FALSE - aes_args <- aes() + aes_args <- list() if (!is.null(colour_by)) { - aes_args$fill <- substitute(`colour_by`) + aes_args$fill <- "colour_by" } if(!is.null(add_border) && add_border && !is.null(colour_by)){ border <- TRUE - aes_args$colour <- substitute(`colour_by`) + aes_args$colour <- "colour_by" } else if(is.null(add_border) && n <= 20) { border <- TRUE - aes_args$colour <- substitute(`colour_by`) + aes_args$colour <- "colour_by" } + aes_args <- lapply(aes_args, function(x) if (!is.null(x)) sym(x)) new_aes <- do.call(aes, aes_args) geom_args <- list(mapping = new_aes, alpha = alpha) if (is.null(colour_by)) { @@ -283,23 +284,24 @@ NULL shape = 21, colour = "grey70") { - aes_args <- aes() + aes_args <- list() fill_colour <- TRUE if (!is.null(shape_by)) { - aes_args$shape <- substitute(`shape_by`) + aes_args$shape <- "shape_by" } if (!is.null(colour_by)) { # Only shapes 21 to 25 can be filled. Filling does not work in other shapes. if(shape >= 21 && shape <= 25){ - aes_args$fill <- substitute(`colour_by`) + aes_args$fill <- "colour_by" } else { - aes_args$colour <- subsitute(`colour_by`) + aes_args$colour <- "colour_by" fill_colour <- FALSE } } if (!is.null(size_by)) { - aes_args$size <- substitute(`size_by`) + aes_args$size <- "size_by" } + aes_args <- lapply(aes_args, function(x) if (!is.null(x)) sym(x)) new_aes <- do.call(aes, aes_args) geom_args <- list(mapping = new_aes, alpha = alpha) if (is.null(colour_by)) { @@ -320,16 +322,17 @@ NULL linewidth = NULL, colour = "grey70") { - aes_args <- aes() + aes_args <- list() if (!is.null(linetype_by)) { - aes_args$linetype <- substitute(`linetype_by`) + aes_args$linetype <- "linetype_by" } if (!is.null(colour_by)) { - aes_args$colour <- substitute(`colour_by`) + aes_args$colour <- "colour_by" } if (!is.null(size_by)) { - aes_args$linewidth <- substitute(`size_by`) + aes_args$linewidth <- "size_by" } + aes_args <- lapply(aes_args, function(x) if (!is.null(x)) sym(x)) new_aes <- do.call(aes, aes_args) geom_args <- list(mapping = new_aes, alpha = alpha) if (is.null(colour_by)) { @@ -361,13 +364,14 @@ NULL .get_edge_args <- function(edge_colour_by, edge_size_by, alpha = 1, size = NULL, layout = NULL){ - aes_args <- aes() + aes_args <- list() if (!is.null(edge_colour_by)) { - aes_args$colour <- substitute(`edge_colour_by`) + aes_args$colour <- "edge_colour_by" } if (!is.null(edge_size_by)) { - aes_args$size <- substitute(`edge_size_by`) + aes_args$size <- "edge_size_by" } + aes_args <- lapply(aes_args, function(x) if (!is.null(x)) sym(x)) new_aes <- do.call(aes, aes_args) geom_args <- list(mapping = new_aes, alpha = alpha) if (is.null(edge_colour_by)) { @@ -397,10 +401,11 @@ NULL } .get_rect_args <- function(colour_by, alpha = 1, colour = "black"){ - aes_args <- aes() + aes_args <- list() if (!is.null(colour_by)) { - aes_args$fill <- substitute(.data[["colour_by"]]) + aes_args$fill <- "colour_by" } + aes_args <- lapply(aes_args, function(x) if (!is.null(x)) sym(x)) new_aes <- do.call(aes, aes_args) geom_args <- list(mapping = new_aes, alpha = alpha, colour = colour) return(list(args = geom_args)) @@ -410,9 +415,10 @@ NULL fill_colour <- TRUE aes_args <- aes() if (!is.null(colour_by)) { - aes_args$colour <- substitute(`colour_by`) - aes_args$fill <- substitute(`colour_by`) + aes_args$colour <- "colour_by" + aes_args$fill <- "colour_by" } + aes_args <- lapply(aes_args, function(x) if (!is.null(x)) sym(x)) new_aes <- do.call(aes, aes_args) geom_args <- list(mapping = new_aes, alpha = alpha) diff --git a/man/plotCCA.Rd b/man/plotCCA.Rd index 714ca498..19479221 100644 --- a/man/plotCCA.Rd +++ b/man/plotCCA.Rd @@ -34,7 +34,7 @@ plotRDA(object, ...) label.size = 4, vec.text = TRUE, repel.labels = TRUE, - sep.group = "‒", + sep.group = "-", repl.underscore = " ", add.significance = TRUE, add.expl.var = TRUE,