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

Two "label=" bugs in ggbarplot #234

Closed
sekharcu opened this issue Jan 4, 2020 · 1 comment
Closed

Two "label=" bugs in ggbarplot #234

sekharcu opened this issue Jan 4, 2020 · 1 comment

Comments

@sekharcu
Copy link

sekharcu commented Jan 4, 2020

We are very happy to have found ggpubr; we find it very useful. I've encountered two apparent bugs, however, both having to do with the label= option. I am very new to GitHub and fairly new to R - I already found that what I had reported earlier as a bug was just that I didn’t have the latest version of ggplot2. But what I report here is seen on multiple Windows and Mac machines, under R3.6.2 with ggpubr as the only package installed, so I am confident about the bugs. Sekhar Ramakrishnan

  1. When I use color= option to display bars of subgroups, the labels are displayed in reverse order within each level of the primary grouping variable:

val8 = c(-10,-20,20,10,-5,-15,15,5)
grp1 = c("A","A","A","A","B","B","B","B")
grp2 = c("X","X","Y","Y","X","X","Y","Y")
df8 = data.frame(val8,grp1,grp2)
ggbarplot(df8,x="grp1",y="val8",color="grp2",add="mean_sd",label=c("AX-15","AY+15","BX-10","BY+10"), position = position_dodge(0.8))
image
If I use label=TRUE, the labels are correct – the right mean is displayed on each bar:
image
There is likely a bug in the way “label=” is handled when labels are provided instead of settling for the means. This appears serious since wrong labels on the bars can lead to misinterpretations; I stumbled on the bug while trying to display statistical significances.

  1. The second, less serious, bug is that the labels on the negative bars are not on top but inside at the bottom of the boxes, even with label=TRUE.

  2. Both problems go away if I create a new group grp12 with four levels:

val8 = c(-10,-20,20,10,-5,-15,15,5)
grp12 = c("A-X","A-X","A-Y","A-Y","B-X","B-X","B-Y","B-Y")
df81 = data.frame(val8,grp12)
ggbarplot(df81,x="grp12",y="val8",add="mean_sd",label=c("AXminus15","AYplus15","BXminus10","BYplus10"))
image
I believe the negative-bar-label-positioning bug has something to do with "position=position_dodge()". If I add that optional argument, which should have no effect when there are no subgroups, the negative bars' labels go to the inside bottoms:
ggbarplot(df81,x="grp12",y="val8",add="mean_sd",label=c("AXminus15","AYplus15","BXminus10","BYplus10"), position = position_dodge(0.8))
image
I hope this report helps Dr Kassambara fix this problem with labeling bars in a two-group situation. As I mention above, ggpubr is a very valuable resource.

kassambara added a commit that referenced this issue Mar 4, 2020
correct labelling of barplots when user specifies labels #234
@kassambara
Copy link
Owner

Thank you for this very clear reproducible example.

Fixed now, thank you for pointing this out

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

2 participants