Skip to content

Commit

Permalink
#73: Expose abs argument at level of geom_stats
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobpwagner committed Oct 28, 2020
1 parent 2596e7b commit 0cdb186
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
9 changes: 6 additions & 3 deletions R/geom_stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
, ...
Expand Down
10 changes: 7 additions & 3 deletions R/ggcyto.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions R/ggcyto_GatingSet.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"]]
Expand Down Expand Up @@ -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"]]
Expand Down

0 comments on commit 0cdb186

Please sign in to comment.