Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass data parameter to Comparisons in stat_compare_means #48

Closed
emcnerny opened this issue Nov 9, 2017 · 8 comments
Closed

Pass data parameter to Comparisons in stat_compare_means #48

emcnerny opened this issue Nov 9, 2017 · 8 comments

Comments

@emcnerny
Copy link

emcnerny commented Nov 9, 2017

I would like to be able to use comparisons for a subset of the data passed to stat_compare_means. Right now you can do this to compare means against a reference group, but not for specified comparisons. For example, here I'm testing against the lowest dose only for the VC group:

df <- ToothGrowth
df$dose <- as.factor(df$dose)
df.VC <- df[df$supp == "VC",]
#Plot using ref.group
ggbarplot(
  df,
  "dose",
  "len",
  color = "supp",
  add = c("point", "mean_sd"),
  xlab = "dose",
  ylab = "len",
  position = position_dodge(0.72)
  ) + stat_compare_means(
    data = df.VC,
    method = "t.test",
    ref.group = "0.5",
    label = "p.format"
  )

Which produces:
image

But this does not work for comparisons (the data parameter is ignored, so it pools the supp groups):

#Plot using comparisons - should have same values, but ignores subsetted data (df.VC)
mycomparisons = list(c("0.5", "1"), c("0.5", "2"))
ggbarplot(
  df,
  "dose",
  "len",
  color = "supp",
  add = c("point", "mean_sd"),
  xlab = "dose",
  ylab = "len",
  position = position_dodge(0.72)
) + stat_compare_means(
  data = df.VC,
  method = "t.test",
  comparisons = mycomparisons
)

Which produces:
image

A separate but related issue, any attempt to pass a label type with comparisons doesn't have the expected result:

#Plot using comparisons - should have same values, but ignores data
mycomparisons = list(c("0.5", "1"), c("0.5", "2"))
ggbarplot(
  df,
  "dose",
  "len",
  color = "supp",
  add = c("point", "mean_sd"),
  xlab = "dose",
  ylab = "len",
  position = position_dodge(0.72)
) + stat_compare_means(
  data = df.VC,
  method = "t.test",
  comparisons = mycomparisons,
  label = "p.format"
)

image

kassambara added a commit that referenced this issue Nov 9, 2017
kassambara added a commit that referenced this issue Nov 9, 2017
@kassambara
Copy link
Owner

Thank you for this well written and reproducible bug report.

Fixed, now!

Install the latest developmental version and kindly confirm that it works.

@emcnerny
Copy link
Author

emcnerny commented Nov 9, 2017

Works great, thanks!

@kassambara
Copy link
Owner

so we can close this issue!

@emcnerny
Copy link
Author

emcnerny commented Nov 9, 2017

Would it be possible to make it so additional params can be passed through to geom_signif? It would make it possible to adjust xmin/xmax and y_position so the tips fall over the correct bars when using subsetted data like in this example.

Edit - NM, I realized that geom_signif doesn't allow both comparisons and x position to be set.

@kassambara kassambara reopened this Nov 9, 2017
@ousabd
Copy link

ousabd commented Jun 29, 2018

Thanks for this great package kassambara.

I was wondering whether emcnerny's last proposition (adjusting the x position so the tips fall over dodged bars in subsetted data) was feasible ?

@kassambara
Copy link
Owner

To add manually p-values from a data frame, use the function stat_pvalue_manual() as described at
#99

@bznes
Copy link

bznes commented Mar 11, 2019

This is a great package but I am having the same problem. I want to overlay p-values for a subset of comparisons ONLY to the treated data to a base plot that looks like this:

ggbarplot(d=d, x = "Group",y="response",color="Treatment",add = "mean_se",position = position_dodge(0.8))
baseplot

When I add stat_compare_means for the treated plot I get this:
my_comparisons=list(c("C1","C2"), c("A","C2"), c("C2","B"), c("C2","D"), c("D","E"), c("D","F")) d.treated <- d[d$Treatment == "treated",] ggbarplot(d=d, x = "Group",y="response",color="Treatment",add = "mean_se",position = position_dodge(0.8))+ stat_compare_means(d.treated,comparisons=my_comparisons)

baseplot_statcompare

However, this is ignoring use of the treated group for stat_compare_means. When I run as facet I see the p-values I actually want displayed on the plot.

ggbarplot(d=d, x = "Group",y="response",color="Treatment",facet.by="Treatment",add = "mean_se",position = position_dodge(0.8))+ stat_compare_means(comparisons=my_comparisons)
baseplot with facet

Is it possible to get the data from the right panel on my first image? Per the above solution I updated all my packages and it still is not working. Can I overlay two ggbarplots like geom_line and geom_point in ggplot? I haven't been able to get that to work.

Thanks!

@bznes
Copy link

bznes commented Mar 15, 2019

Problem solved...despite a recent download, sessionInfo() revealed I was running an older version of ggpubr package, updating to ggpubr_0.2 fixed my problem. Now my question is if you can recenter the comparison brackets over the group being compared (treated, not centered between the two treatment levels).
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants