Skip to content

Commit

Permalink
Make remove.bracket work better
Browse files Browse the repository at this point in the history
i.e. more flexible to different potential
structures of the input data.frame.

Also allow the each.vs.ref columns to be
specified the other way around, which works better
if the reference sample is on the right e.g.
dose == 2.
  • Loading branch information
csdaw committed Feb 14, 2021
1 parent 4f42cdb commit cc309f1
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions R/add_pvalue.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,16 @@ add_pvalue <- function(data,

# check for remove.bracket
# should stay before (!is.null(x))
if (remove.bracket) {
if (remove.bracket & !is.null(xmax)) {
xmin.length <- length(unique(data[[xmin]]))
if (xmin.length == 1) {
xmax.length <- length(unique(data[[xmax]]))
if (xmin.length == 1 & xmax.length >= 2) {
xmin <- xmax
xmax <- NULL
}
else if (xmin.length >= 2 & xmax.length == 1) {
xmax <- NULL
}
}

# determine the type of comparisons: one_group, two_groups, each_vs_ref, pairwise
Expand All @@ -155,8 +159,9 @@ add_pvalue <- function(data,
}
else if (ngroup1 >= 2 & ngroup2 >= 2) {
comparison <- "pairwise"
} else {
stop("Make sure that xmin and xmax columns exist in the data.")
}
else if (ngroup1 >= 2 & ngroup2 == 1) {
comparison <- "each_vs_ref"
}
} else {
if(ngroup1 >= 1) {
Expand Down Expand Up @@ -206,10 +211,6 @@ add_pvalue <- function(data,

# draw brackets else draw p-value text
if (pvalue.geom == "bracket") {
if (identical(data$xmin, data$xmax) | remove.bracket) {
bracket.size = 0
}

params <- list(
group = 1:nrow(data),
label = "label", xmin = "xmin", xmax = "xmax",
Expand Down

0 comments on commit cc309f1

Please sign in to comment.