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: Multiple groups with error bars only work with color argument #71

Closed
j3ypi opened this issue Mar 12, 2018 · 18 comments
Closed

Comments

@j3ypi
Copy link

j3ypi commented Mar 12, 2018

If one uses fill instead of color, one wouldn't get an error bar within the categories, but a centered error bar for each category on the x-axis. The combination of both arguments is possible though, but it's useless, since one can't see the bottom half of the error bar.

Here's a short reproducable example:

library(tidyverse)
library(ggpubr)

df <- tibble(
  iq = rnorm(100, 100, 15),
  condition = rep(c("A", "B"), each = 50),
  time = rep(c("t1", "t2", "t1", "t2"), each = 25)
)
ggbarplot(df,
      x = "condition",
      y = "iq",
      fill = "time",
      palette = "grey",
      add = "mean_se", 
      position = position_dodge(0.8))
@yfangumich
Copy link

I've had the same problem.

@kassambara
Copy link
Owner

For customizing the error bar, you should specify the argument add.params:

ggbarplot(df,
          x = "condition",
          y = "iq",
          fill = "time",
          palette = "grey",
          add = "mean_se",  add.params = list(color = "time"),
          position = position_dodge(0.8))

@j3ypi
Copy link
Author

j3ypi commented Jun 17, 2018

Your code doesn't work like its supposed to. It still produces error bars in the same color as the barplot, which makes it impossible to see the lower half.

What I want is this:

df %>% 
  group_by(condition, time) %>% 
  summarise(IQ = mean(iq),
            se = sd(iq) / sqrt(n())) %>% 
  ggplot(aes(x = condition, y = IQ, fill = time)) +
  geom_bar(width = 0.85, position = position_dodge(width = 0.9), stat = "identity") +
  geom_errorbar(aes(ymin = IQ - se, ymax = IQ + se),
                width = .2,                   
                position = position_dodge(0.9)) + 
  scale_fill_grey() +
  theme_pubr()

The problem wouldn't exist, if the color argument would work intuitivly like fill.

@kassambara kassambara reopened this Jun 17, 2018
@cnnmat
Copy link

cnnmat commented Aug 2, 2018

Same problem here.

@kassambara
Copy link
Owner

With the latest developmental version of ggpubr, you can do this:

# Required packages and demo data
library(tidyverse)
library(ggpubr)
df <- tibble(
  iq = rnorm(100, 100, 15),
  condition = rep(c("A", "B"), each = 50),
  time = rep(c("t1", "t2", "t1", "t2"), each = 25)
)


# Visualization
ggbarplot(df, x = "condition", y = "iq", 
          fill = "time", palette = "grey",
          add = "mean_se",  add.params = list(group = "time"),
          position = position_dodge(0.8))

rplot45

@j3ypi
Copy link
Author

j3ypi commented Aug 12, 2018

Works like a charm - thanks!

@kassambara
Copy link
Owner

so we can close the issue

@sophiahng
Copy link

It does not work for me.
It produces error codes
Error in (function (p, add = NULL, color = "black", fill = "white", width = 1, :
unused argument (group = "time")
What is the problem?

@j3ypi
Copy link
Author

j3ypi commented Aug 21, 2018

You have to install the current development version via

devtools::install_github("kassambara/ggpubr")

@sophiahng
Copy link

Problem solved. Thanks!

@cnnmat
Copy link

cnnmat commented Aug 24, 2018

Merci beaucoup !

@dkagro1991
Copy link

Yielddata.xlsx
i want to create a barplot on data yld and yld2 (sheet2) in r studio after importing my excel sheet into r studio. I am foloowing the step provided by you but not able to creat one. plz help me with the steps and codes. Thankyou

@kassambara
Copy link
Owner

grps column should be organized as highlighted in red.

groups

@elenichri
Copy link

Hello,
I have a similar issue but with adding points after doing the barplot: The points are added in the middle of the group. I want however to add them at each bar of the group. So the x for the points should be different from the x for the x for the barplot. How can I do that? Here is my code:

ggbarplot(melted_fig4a.dmso, x = 'drug', y = 'value', width=0.8, add = c("mean_sd"), add.params = list(color='black', group='compound_concentration'), font.xtickslab = 20, font.x=22, font.ytickslab = 20, font.y=22, ylim=c(0,15), color='compound_concentration', #no, group by concentration fill='compound_concentration', position=position_dodge(0.8), palette='grey', x.text.angle=90) + geom_point(size=2, data= melted_fig4a.dmso, aes(x=treatment, y=value))

This adds the points in different columns AFTER the bars of each group

Here are the top 15 lines of the melted_fig4a.dmso
treatment compound_concentration replicate value drug
None 1 rep1 0.33 None
Dima 1 1 rep1 0.73 Dima
Dima 10 2 rep1 1.03 Dima
Dima 100 3 rep1 2.49 Dima
Quin 1 1 rep1 0.74 Quin
Quin 10 2 rep1 0.46 Quin
Quin 100 3 rep1 0.53 Quin
Colc 0.0025 1 rep1 1.35 Colc
Colc 0.005 2 rep1 2.41 Colc
Colc 0.01 3 rep1 1.53 Colc
Meb 0.05 1 rep1 0.38 Meb
Meb 0.1 2 rep1 1.11 Meb
Podo 0.005 1 rep1 0.68 Podo
Podo 0.01 2 rep1 1.02 Podo
Dino 1 1 rep1 0.74 Dino

I would very much appreciate your help

Eleni

@dkagro1991
Copy link

dkagro1991 commented May 24, 2023 via email

@marinaaa118
Copy link

marinaaa118 commented May 25, 2023 via email

@dkagro1991
Copy link

dkagro1991 commented May 26, 2023 via email

@marinaaa118
Copy link

marinaaa118 commented May 26, 2023 via email

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

8 participants