From 0cdb186d0c624b8be35d9ed883204c2290f031c4 Mon Sep 17 00:00:00 2001 From: Jacob Wagner Date: Wed, 28 Oct 2020 13:53:26 -0700 Subject: [PATCH] #73: Expose abs argument at level of geom_stats --- R/geom_stats.R | 9 ++++++--- R/ggcyto.R | 10 +++++++--- R/ggcyto_GatingSet.R | 2 ++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/R/geom_stats.R b/R/geom_stats.R index 2bf6f7b..4a80a70 100644 --- a/R/geom_stats.R +++ b/R/geom_stats.R @@ -7,7 +7,10 @@ #' @param gate a 'filterList` or character (represent as a population node in GatingSet) #' if not supplied, ggcyto then tries to parse the gate from the first geom_gate layer. #' @param negated whether the gate needs to be negated -#' @param adjust adjust the position of the centroid. from 0 to 1. +#' @param adjust adjust the position of the centroid. from 0 to 1. +#' @param abs If TRUE, the centroid will be calculated based on the full data range rather than +#' the particular gate. This allows the adjust parameter to start from the center of the plot as opposed +#' to the center of the gate. #' @param label.padding,label.size arguments passed to geom_label layer #' @param digits control the stats format #' @param ... other arguments passed to geom_label layer @@ -27,11 +30,11 @@ #' # display gate name and percent #' p + geom_gate(c("CD4", "CD8")) + geom_stats(type = c("gate_name", "percent")) geom_stats <- function(gate = NULL, ..., value = NULL, type = "percent", negated = FALSE, adjust = 0.5 - , label.padding = unit(0.05, "lines"), label.size = 0, digits = 3){ + , abs = FALSE, label.padding = unit(0.05, "lines"), label.size = 0, digits = 3){ type <- unlist(lapply(type, function(stat_type)match.arg(stat_type, c("percent", "count", "gate_name")))) structure( - list(gate = gate, value = value, type = type, negated = negated, adjust = adjust, digits = digits + list(gate = gate, value = value, type = type, negated = negated, adjust = adjust, abs = abs, digits = digits , geom_label_params = list(label.padding = label.padding , label.size = label.size , ... diff --git a/R/ggcyto.R b/R/ggcyto.R index a12aa2d..4cdefa4 100644 --- a/R/ggcyto.R +++ b/R/ggcyto.R @@ -365,6 +365,7 @@ as.ggplot <- function(x, pre_binning = FALSE){ negated <- e2[["negated"]] adjust <- e2[["adjust"]] + abs <- e2[["abs"]] digits <- e2[["digits"]] if(length(trans)>0) { @@ -379,9 +380,12 @@ as.ggplot <- function(x, pre_binning = FALSE){ for(gate in gates_parsed){ if(length(trans)>0) gate <- transform(gate, translist) - - #TODO: compute the actual data range from population data - abs <- is(gate[[1]], "booleanFilter")#bypass stats_postion computing by set abs to true to use data_range as gate_range(as a hack for now) + + # Honor manual choice of abs == TRUE + if(!abs){ + #TODO: compute the actual data range from population data + abs <- is(gate[[1]], "booleanFilter")#bypass stats_postion computing by set abs to true to use data_range as gate_range(as a hack for now) + } stats <- compute_stats(fs, gate , type = stat_type diff --git a/R/ggcyto_GatingSet.R b/R/ggcyto_GatingSet.R index 866edbc..23f511e 100644 --- a/R/ggcyto_GatingSet.R +++ b/R/ggcyto_GatingSet.R @@ -109,6 +109,7 @@ add_ggcyto_gs <- function(e1, e2){ }else if(is(e2, "GeomStats")){ adjust <- e2[["adjust"]] + abs <- e2[["abs"]] #grab the nodes info from previous gate layers nodes.geom_gate <- e1[["nodes"]] @@ -149,6 +150,7 @@ add_ggcyto_gs <- function(e1, e2){ , type = stat_type , negated = negated , adjust = adjust + , abs = abs , digits = digits ) , e2[["geom_label_params"]]