diff --git a/NEWS.md b/NEWS.md index 6c80d680..c3994a15 100644 --- a/NEWS.md +++ b/NEWS.md @@ -13,6 +13,8 @@ ## Bug fixes +- The option `ref.group` was only considered when the grouping variable contains more than two levels. In that case, each level is compared against the specified reference group. Now, `ref.group` option is also considereded in two samples mean comparisons ([@OwenDonohoe, #118](https://github.com/kassambara/ggpubr/issues/118) + - Now, `ggqqplot()` reacts to the argument `conf.int.level` ([@vsluydts, #123](https://github.com/kassambara/ggpubr/issues/123) - Added error bar color is now inherited from the main plot ([@JesseRop, #109](https://github.com/kassambara/ggpubr/issues/109) diff --git a/R/compare_means.R b/R/compare_means.R index 6f9fa0c8..4041e08d 100644 --- a/R/compare_means.R +++ b/R/compare_means.R @@ -156,6 +156,9 @@ compare_means <- function(formula, data, method = "wilcox.test", if(is.factor(group.vals)) group.levs <- levels(group.vals) else group.levs <- unique(group.vals) + if(ref.group %in% group.levs){ + data[, group] <- stats::relevel(group.vals, ref.group) + } if(ref.group == ".all."){ data <- data %>% diff --git a/R/stat_compare_means.R b/R/stat_compare_means.R index d7f3988e..469e562f 100644 --- a/R/stat_compare_means.R +++ b/R/stat_compare_means.R @@ -199,7 +199,7 @@ StatCompareMeans<- ggproto("StatCompareMeans", Stat, #:::::::::::::::::::::::::::::::::::::::::::::::::: method.args <- method.args %>% .add_item(data = data, method = method, - paired = paired, ref.group = ref.group, + paired = paired, ref.group = as.character(ref.group), symnum.args = symnum.args) if(.is.multiple.grouping.vars){ @@ -212,6 +212,7 @@ StatCompareMeans<- ggproto("StatCompareMeans", Stat, .add_item(formula = y ~ x) .test <- do.call(compare_means, method.args) } + print(.test) pvaltxt <- ifelse(.test$p < 2.2e-16, "p < 2.2e-16", paste("p =", signif(.test$p, 2)))