Git Product home page Git Product logo

Comments (3)

kassambara avatar kassambara commented on August 15, 2024 4

Hi,

specifying label.y in aes() is not supported.

You can do this:

ggplot(test, aes(x=group, y = values, fill=group)) + 
  geom_boxplot() +
  geom_blank(aes(y=ymax*3))+
  facet_wrap(~vars, scales = 'free') + 
  stat_compare_means(comparisons=list(c("A","B")), label.y = 20)

When scales = 'free', it's even better to use label.y.npc:

ggplot(test, aes(x=group, y = values, fill=group)) + 
  geom_boxplot() +
  geom_blank(aes(y=ymax*3))+
  facet_wrap(~vars, scales = 'free') + 
  stat_compare_means(label.y.npc = 0.4)

rplot

Let's keep this issue open, I need to improve annotation of the different facet panels

from ggpubr.

miguelroboso avatar miguelroboso commented on August 15, 2024

Thanks @kassambara .
Surprisingly enough, label.y.npc does not work when I specify the comparisons.

This code

  geom_boxplot() +
  geom_blank(aes(y=ymax*3))+
  facet_wrap(~vars, scales = 'free') + 
  stat_compare_means(comparisons=list(c("A","B")),label.y.npc = 0.4)

actually still returns the labels at the top:

plot_zoom_png

from ggpubr.

kassambara avatar kassambara commented on August 15, 2024

now, you can compute p-value and add it manually at any position.

In the following example, we'll use the ToothGrowth data. We'll compare supp levels after grouping the data by dose.

# Statistical test
library("rstatix")  # https://github.com/kassambara/rstatix
stat.test <-  ToothGrowth %>%
  group_by(dose) %>%
  t_test(len ~ supp) %>%
  adjust_pvalue() %>%
  add_significance("p.adj")
stat.test
# A tibble: 3 x 9
   dose   .y. group1 group2  statistic      p method  p.adj p.adj.signif
                           
1   0.5   len     OJ     VC  3.1697328 0.0064 T-test 0.0128            *
2   1.0   len     OJ     VC  4.0327696 0.0010 T-test 0.0030           **
3   2.0   len     OJ     VC -0.0461361 0.9600 T-test 0.9600           ns
# Visualization
library(ggpubr)
ggboxplot(
  ToothGrowth, x = "supp", y = "len",
  color = "supp", palette = "jco",
  ylim = c(0, 40)
) +
  facet_wrap(~dose) +
  stat_pvalue_manual(stat.test, label = "p.adj", y.position = 35)

rplot

Note that, the option y.position can be a numeric vector with length = the nombre of p-values to add. It can be also a column name in the stat.test data frame.

from ggpubr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.