Open kassambara opened 5 years ago
Hi Alboukadel,
thank you for the excellent issue description and the reproducible example. Please execuse the delay, I am currently travelling (until the end of the month), and although I do have my laptop with me, I cannot promise that I will find time to look into the underlying problem and implement a fix.
But, i would be very happy to accept a pull request. From your repos, I have the impression that you have the necessary experience with ggplot extensions ;)
Best, Constantin
Hi Constatin,
Thank you again for this awesome package.
I found a quick fix to my issue:
group
in aes()stat.test$group <- 1:nrow(stat.test)
p + geom_signif(
aes(xmin = xmin, xmax = xmax, y_position = y_position, annotations = signif, group = group),
data = stat.test, manual = TRUE, tip_length = 0, vjust = 0.5
)
From my point of view, when manual = TRUE
, then each annotation can be automatically considered as a different group.
If you think that it's a good user-experience to have this grouping done automatically, then the function geom_signif()
can be simply modified as follow:
Replacing :
group=if(manual){rep(data$group, times=3)}
(in line: https://github.com/const-ae/ggsignif/blob/4fbacff05ab349b4f10373b3b0bdbb4b70df5d7f/R/significance_annotation.R#L129)
by:
group=if(manual){rep(1:xmin, times=3)}
If this modification is not necessary, then we can close this issue
Have a good trip!
Alboukadel
Thank you again for this awesome package.
Well, thank you for most its downloads :)
I found a quick fix to my issue
That's great to hear. And for your suggestion, I will have to have a more thorough look, so I will leave the issue open and take another look when I am back.
Have a good trip!
Thanks.
I found a quick fix to my issue:
- Adding group column: each row (i.e., comparison) is considered as a different group
- Specifying the
group
in aes()
Hi, Alboukadel, great work. It solved my problem. Thank you !
@shiyun09 you're welcome, I'm happy to know that it helps
@kassambara thank you, I run in this problem and your workaround was exactly what I needed.
I use rstatix
and add manually the signf. values and it did not work when the annotations were the same. Now I use simply the p.adj
column as a dummy group.
custom_p <- DATA %>% rstatix::dunn_test(costs ~ 0 + tri_size, p.adjust.method = "holm")
custom_p <- pwc %>% rstatix::add_xy_position(x = "tri_size")
ggplot(data, aes()) + geom_boxplot() + ...
ggsignif::geom_signif(
data=custom_p,
aes(xmin = xmin, xmax = xmax, annotations = p.adj.signif, y_position = y.position, group = p.adj),
manual=TRUE)
With group:
Without group:
Cheers Hannes
I am revisiting this, but I can't actually reproduce the original behavior. I am not sure if this has something to do with ggplot2
itself having changed:
library(ggplot2)
library(ggsignif)
p <- ggplot(ToothGrowth, aes(supp, len)) +
geom_boxplot(aes(color = dose))
s <- stat.test <- data.frame(
stringsAsFactors=FALSE,
p.adj = c(0.000176, 3.96e-06, 0.0392, 1.36e-06, 1.4e-07, 9.16e-05),
signif = c("****", "****", "****", "****", "****", "****"),
signif2 = c("a", "b", "c", "d", "e", "f"),
y_position = c(31.827, 33.5295, 35.232, 34.917, 37.1445, 39.372),
xmin = c(0.7, 0.7, 1, 1.7, 1.7, 2),
xmax = c(1, 1.3, 1.3, 2, 2.3, 2.3),
group = rep(1:2, each = 3),
supp = as.factor(rep(c("OJ", "VC"), each = 3))
)
s
#> p.adj signif signif2 y_position xmin xmax group supp
#> 1 1.76e-04 **** a 31.8270 0.7 1.0 1 OJ
#> 2 3.96e-06 **** b 33.5295 0.7 1.3 1 OJ
#> 3 3.92e-02 **** c 35.2320 1.0 1.3 1 OJ
#> 4 1.36e-06 **** d 34.9170 1.7 2.0 2 VC
#> 5 1.40e-07 **** e 37.1445 1.7 2.3 2 VC
#> 6 9.16e-05 **** f 39.3720 2.0 2.3 2 VC
p + geom_signif(
aes(xmin = xmin, xmax = xmax, y_position = y_position, annotations = signif2),
data = stat.test, manual = TRUE, tip_length = 0
)
#> Warning: Ignoring unknown aesthetics: xmin, xmax, y_position, annotations
Created on 2021-01-13 by the reprex package (v0.3.0)
Closing this as I can no longer reproduce this behavior. Please re-open it with a reprex
if you can reproduce this issue again.
I found a way of replicating the original reprex. The variable "dose" from "ToothGrowth" needs to be a factor to enable the color mapping. I suppose the OP (@kassambara) changed "ToothGrowth" before posting.
library(ggplot2)
library(ggsignif)
p <- ggplot(ToothGrowth, aes(supp, len)) +
geom_boxplot(aes(color = as.factor(dose)))
s <- stat.test <- data.frame(
stringsAsFactors=FALSE,
p.adj = c(0.000176, 3.96e-06, 0.0392, 1.36e-06, 1.4e-07, 9.16e-05),
signif = c("****", "****", "****", "****", "****", "****"),
signif2 = c("a", "b", "c", "d", "e", "f"),
y_position = c(31.827, 33.5295, 35.232, 34.917, 37.1445, 39.372),
xmin = c(0.7, 0.7, 1, 1.7, 1.7, 2),
xmax = c(1, 1.3, 1.3, 2, 2.3, 2.3),
group = rep(1:2, each = 3),
supp = as.factor(rep(c("OJ", "VC"), each = 3))
)
p + geom_signif(
aes(xmin = xmin, xmax = xmax, y_position = y_position, annotations = signif),
data = stat.test,
manual = TRUE, tip_length = 0
)
#> Warning: Ignoring unknown aesthetics: xmin, xmax, y_position, annotations
Created on 2021-11-09 by the reprex package (v2.0.1)
I agree with Alboukadel when he says that
it's a good user-experience to have this grouping done automatically
I hope to see this added/fixed soon!
Best, Mateus.
Hi,
As described in issue https://github.com/const-ae/ggsignif/issues/6, annotation that contain duplicate contents does not work for grouped plots.
Let's start by some reproducible examples.
Demo data and plot:
Th following R code works because all annotation contents are distinct:
This one does not work because annotation contents are duplicated:
A workaround has been provided in discussion: https://github.com/const-ae/ggsignif/issues/6
My problem is that, the above solution does not work when facet is used:
Aesthetic mapping is better for faceting but annotations are not displayed correctly:
Any suggestions?