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

ggbarplot help #28

Closed
kassambara opened this issue Aug 26, 2017 · 10 comments
Closed

ggbarplot help #28

kassambara opened this issue Aug 26, 2017 · 10 comments

Comments

@kassambara
Copy link
Owner

@kassambara kassambara commented Aug 26, 2017

(e-mail from user)

I have made the plot you can see attached below.

ggbarplot(data.Tmel, x = "continent", y="readNO_Tmel", fill="continent", color = c("#1F78B4","#33A02C"), add="mean_se", position=position_dodge(0.8),
          label = TRUE, lab.pos = "in", lab.col = "white", lab.size = 3.5) +
stat_compare_means(method = "wilcox.test", comparisons = list(c("Europe","Australia")), label="p.format", label.y = 4000) +
scale_fill_manual(values = c("#1F78B4","#33A02C")) +
labs(title="(A)",  x="", y = "Read number") +
theme(plot.title = element_text(size = 9, face = "bold", hjust = 0)) + #hjust = 0.5, to center
theme(axis.title = element_text(face="bold", size = 9)) +  
theme(axis.text.x = element_text(size=9, face = "bold", angle = 90, hjust = 1, vjust=0.5, color="black")) +
theme(axis.text.y = element_text(size=7)) +
scale_y_continuous(breaks = seq(0, 4000, 500)) +
theme(legend.position="none")

Is there a way to customize the bracket whiskers?
is there a way to round to 1 decimal the number plotted in white within the bars?
Moreover I am using the flag label="p.format" but I still have the significance code instead of the p-value, where is my msitake there?

@kassambara
Copy link
Owner Author

@kassambara kassambara commented Aug 26, 2017

  • New argument lab.nb.digits in ggbarplot(). Integer indicating the number of decimal places (round) to be used . Example: lab.nb.digits = 2.

  • New argument tip.length in stat_compare_means(). Numeric vector with the fraction of total height that the bar goes down to indicate the precise column. Default is 0.03. Can be of same length as the number of comparisons to adjust specifically the tip lenth of each comparison. For example tip.length = c(0.01, 0.03).

  • stat_compare_means() now reacts to label = "p.format" when comparisons specified (#28).

Example:

library(ggpubr)
ggbarplot(ToothGrowth, x = "dose", y = "len",
          add = "mean_se", 
          error.plot = "upper_errorbar",
          label = TRUE, 
          lab.nb.digits = 1, # Round to 1 decimal 
          lab.pos= "in") +
  stat_compare_means(method = "wilcox.test", 
                     comparisons = list(c("0.5","1"), c("1","2")), 
                     label="p.format",
                     label.y = 30, 
                     tip.length = 0.03 # customize the bracket whiskers
                     )

rplot

@Gian77
Copy link

@Gian77 Gian77 commented Aug 28, 2017

Hello,
both of the arguments you suggested to add are not working on my dataset.
Also, in the example you posted above the argument lab.nb.digits = 1, # Round to 1 decimal, didn't work either as on the plot I still see 2 decimals in 2 bars.
You report "tip.length = c(0.01, 0.03)" as an argument to customize bracket's whiskers, but then you have just "tip.length = 0.03" in your code. Again, both of those didn't work for me. Is there a complete list of ggbarplot() arguments as those you mentioned aren't reported anywhere in the package documentation?
Thanks,
G.

That's the code I've run

ggbarplot(data.test, x = "site_brule", y="readNO_Tmel", fill="brule", color = "brule", error.plot = "upper_errorbar", palette =c("#A6CEE3","#1F78B4"), add="mean_se", position=position_dodge(0.8), legend="none") +
stat_compare_means(method = "kruskal.test", label.x.npc=0.1, label.y =16000, size=3.5) +
stat_compare_means(method = "wilcox.test", comparisons = my_comparisons_eur, label ="p.signif", label.y =14000, tip.length = 0.1) +
labs(title="(D)", x="", y="Read number") +
.....

rplot01

Moreover, now also N.S. comparisons aren't showing up on the plot and I don't know why, do you?

And,

ggbarplot(data.test, x = "continent", y="readNO_Tmel", fill="continent", color="continent",
palette = c("#1F78B4","#33A02C"), add="mean_se", error.plot = "upper_errorbar",
label = TRUE, lab.pos = "in", lab.col = "white", lab.size = 3.5, lab.nb.digits = 2) +
stat_compare_means(method = "wilcox.test", comparisons = list(c("Europe","Australia")), label="p.format", label.y = 4000) +
...

rplot02

Thanks again!
G.

kassambara added a commit that referenced this issue Aug 29, 2017
kassambara added a commit that referenced this issue Aug 29, 2017
@kassambara
Copy link
Owner Author

@kassambara kassambara commented Aug 29, 2017

Hi,

I forgot to push the changes to github. Please, Install the latest developmental version and try it. It should work, thanks.

@Gian77
Copy link

@Gian77 Gian77 commented Aug 29, 2017

Hello again,
thanks for your efforts in upgrading your scripts, now it looks very good. Please see below (sorry for covering site locations but I still don't have the permit to show them).

test_plot

I have used ggarrange() to create a multi-plot. I have a question also, is there a way to manage the dimension of each individual plot so I can try to reach the same bar width? For example to have the plot A and C with same bar width. Also in plot B and D there are not the same number of bars and would be nice to make the bars having the same width. I played with position=position_dodge(width=...) and width=... but they not seem to work.

Thanks again,
G.

@kassambara
Copy link
Owner Author

@kassambara kassambara commented Aug 29, 2017

Hi,

A simple suggestion would be to play with the argument width in ggbarplot() for changing the width of bars.

Use different bar widths for the different plots. For example:

library("ggpubr")
p1 <- ggbarplot(ToothGrowth, x = "dose", y = "len",
          add = "mean_se", 
          error.plot = "upper_errorbar",
          width = 0.5) 

p2 <- ggbarplot(ToothGrowth, x = "supp", y = "len",
                add = "mean_se", 
                error.plot = "upper_errorbar",
                width = 0.35) 

ggarrange(p1, p2, nrow = 2)

rplot

You can also read the different options presented at http://www.sthda.com/english/wiki/ggplot2-easy-way-to-mix-multiple-graphs-on-the-same-page. You can go directly to the section: "Change column/row span of a plot"

@Gian77
Copy link

@Gian77 Gian77 commented Sep 5, 2017

Hello,
sorry for the delay of this answer. I have figure it out how to plot multiple graphs in one single plot using cowplot , thank you for the link you provided.

Anyway, I am having the following error with some of the data

Warning
message:
Computation failed in stat_signif():
missing value where TRUE/FALSE needed

Do you know why?

.ggboxplot(data_ecm.div, x = "site_b", y = "richness", fill= palette_site_all, >color=palette_site_all,
palette=palette_site_all, outlier.colour="black", outlier.size=0.7, legend="none") +
stat_compare_means(method = "kruskal.test", label.x.npc=0.1, label.y =60, size=2.3) +
stat_compare_means(label = "p.signif", method = "wilcox.test", label.y =50, comparisons = my_comparisons_all) +
...

This is how my data look like

richness shannon simpson continent site b cont_b site_b
AU_ITS_A1F 10 0.31501981 0.109584607 Australia Yarra outside Australia.outside Yarra.outside
AU_ITS_A1N 4 0.09954602 0.034864516 Australia Yarra inside Australia.inside Yarra.inside
AU_ITS_A2F 4 0.01757313 0.004339729 Australia Yarra outside Australia.outside Yarra.outside`
...

Thanks a lot,
G.

@kassambara
Copy link
Owner Author

@kassambara kassambara commented Sep 14, 2017

Hi,

Would you, please, provide a reproducible example with a demo data set?

Thanks

@Gian77
Copy link

@Gian77 Gian77 commented Sep 18, 2017

Too late, I was able to fix it :)
Thanks,
Gian

@kassambara kassambara closed this Sep 21, 2017
@lisaos
Copy link

@lisaos lisaos commented Nov 8, 2017

Hi Gian77,

I'm experiencing the same problem as you describe, how did you end up fixing yours?
Thanks,
Lisa

@Gian77
Copy link

@Gian77 Gian77 commented Nov 8, 2017

Hello Lisa,
I have checked my dataset and I had bad names in the site_b variable. After I relabel them, the script plot the graph as I wanted. Check you dataset and look if the comparisons = my_comparisons_all match the names you have in your dataset for the variable you are using in the statistical test.
Hope it helps,
G.

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

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.