 # to add the significative comparison

Dear Friends,
I don't know how to add the significative comparison between the histogram as in this example:

Is there a particular string? I don't know how to add the significative comparison - "*" - on the histogram: is there a package that I need to complete my analysis? Thanks!

1 Like

GREAT!!! It's the right solution! I want calculate the significance of a difference between groups and add the annotation to the plot in a single line.
But... I don't understand how can I report the script in my analysis?

In my hospital dataset, I have a column "PATIENT SEX" and another column "AGE": I want realize two plot and add the significance of a difference between groups in a single line on the plots.

In your link:

``````ggplot(iris, aes(x=Species, y=Sepal.Length)) +
geom_boxplot() +
geom_signif(comparisons = list(c("versicolor", "virginica")),
map_signif_level=TRUE)
``````

if I write:

``````ggplot(NAMESET, aes(x=PATIENT SEX, y= AGE)) +
geom_boxplot() +
geom_signif(comparisons = list(c("0", "1")),
map_signif_level=TRUE)
``````

I obtain this message:

``````Error in f(...) :
Can only handle data with groups that are plotted on the x-axis
Inoltre: Warning message:
Continuous x aesthetic -- did you forget aes(group=...)?
``````

I don't understand the error: How can I write my script?

Thanks for your help!!!

A reproducible example would help - you'd likely discover that if your `PATIENT SEX` column is numeric then your standalone boxplot doesn't have groups (especially not two labelled "0" and "1"). Converting the SEX variable to factor is the first step towards getting this right. Here's a reprex which shows it working. Hope that helps.

``````library(ggplot2)
library(ggsignif)

set.seed(1)

d <- data.frame(SEX = c(rep(0, 10), rep(1, 10)),
AGE = c(sample(20:40, 10, replace = TRUE), sample(30:50, 10, replace = TRUE)))
ggplot(d, aes(factor(SEX), AGE)) +
geom_boxplot() +
geom_signif(comparisons = list(c("0", "1")),
map_signif_level=TRUE)
#> Warning in wilcox.test.default(c(23, 26, 20, 21, 30, 33, 37, 38, 20, 40), :
#> cannot compute exact p-value with ties
`````` Created on 2020-06-16 by the reprex package (v0.3.0)

Thanks for your help!! I solved this problem, using factor variable.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.