const-ae / ggsignif

Easily add significance brackets to your ggplots
https://const-ae.github.io/ggsignif/
GNU General Public License v3.0
593 stars 43 forks source link

comparison by group in legend #58

Closed rysterzhu closed 5 years ago

rysterzhu commented 5 years ago

data: condition Sample percentage A early 0.5 A late 0.4 B early 0.2 B late 0.1 ...

ggplot(data, aes(x=condition,y=Percentage,fill=Sample)) + geom_boxplot(alpha=0.5,position = position_dodge2(),outlier.shape = NA) + ggsignif::geom_signif(comparisons = list(c("early", "late")), y_position = 8,test = "wilcox.test", map_signif_level=TRUE)

Is possible compare "early" and "late" in each condition? Thanks

const-ae commented 5 years ago

No, sorry. At the moment there is no easy way to compare between different groups.

In the README, I give an example how to do it manually

# Calculate annotation
anno <- t.test(iris[iris$Petal.Width > 1 & iris$Species == "versicolor", "Sepal.Width"], 
               iris[iris$Species == "virginica", "Sepal.Width"])$p.value

# Make plot with custom x and y position of the bracket
ggplot(iris, aes(x=Species, y=Sepal.Width, fill=Petal.Width > 1)) +
  geom_boxplot(position="dodge") +
  geom_signif(annotation=formatC(anno, digits=1),
              y_position=4.05, xmin=2.2, xmax=3, 
              tip_length = c(0.2, 0.04))

dodge_comparison-1