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

Three "label=" bugs in ggbarplot #233

Closed
sekharcu opened this issue Dec 23, 2019 · 2 comments
Closed

Three "label=" bugs in ggbarplot #233

sekharcu opened this issue Dec 23, 2019 · 2 comments

Comments

@sekharcu
Copy link

We are very happy to have found ggpubr; we find it very useful. I've encountered 3 apparent bugs, however, all having to do with the label= option. This is my first post on GitHub, so please excuse any inappropriate language (quite unintended). I should also say that I am fairly new to R, so the possibility is real that I am quite wrong about there being bugs in ggbarplot. Sekhar Ramakrishnan

  1. The label=c(...) option puts the labels on the wrong bars if there are both positive and negative bars, and the negative bars do not all precede the positive bars. The label for the first negative bar is put on the first bar, with the other labels following the sequence in label=c(...), and the skipped labels appearing on the bars at the end. Here is a simple example with just two bars:

vals = c(20,10,-10,-20)
ab = c("Aplus","Aplus","Bminus","Bminus")
dfpm = data.frame(vals,ab)
ggbarplot(dfpm,x="ab",y="vals",add="mean_sd",label=c("label-A","label-B"))
image
If I call the groups Bplus and Aminus so that the negative bar comes first, the labeling is correct:
vals = c(20,10,-10,-20)
ba = c("Bplus","Bplus","Aminus","Aminus")
dfmp = data.frame(vals,ba)
ggbarplot(dfmp,x="ba",y="vals",add="mean_sd",label=c("label-A","label-B"))
image

  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 "x" (even though the negative bar comes first within each level):

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

  1. If I use label=TRUE, the correct mean is displayed on each bar but the negative means are shown inside on the bottom of the bar. [This is in contrast to what we see in the mean within group for ggdensity(gghistogram) missing if data have NA values #1 above where the label is on the top of the bar, whether positive or negative.]
    image
@sekharcu
Copy link
Author

Sorry to be the first one to comment on my own bug report, but I have learned since my post that the first bug I reported is machine-specific. Over the past 24h, I have tested the bugs on a Windows 7 laptop, a Windows 10 desktop, and two Mac laptops. The first bug is machine-specific, so I want to retract it, except for point 3 below. The first two bugs I report here were seen on all four machines.

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

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")
df82 = data.frame(val8,grp1,grp2)
ggbarplot(df82,x="grp1",y="val8",color="grp2",add="mean_sd",label=c("AXminus15","AYplus15","BXminus10","BYplus10"), position = position_dodge(0.8))
image

  1. Note as well that the labels on the negative bars are not on top but inside at the bottom of the boxes. This does not happen 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 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

  1. Returning to the first bug I reported yesterday, we see in the second graph above that the second and third bar labels are interchanged (due to a positive bar preceding a negative bar). This is machine-specific since I could not replicate it on all four machines. I find it interesting that the labels are correct in the last graph, with "position=position_dodge(0.8)" (though the negative bars' labels are vertically incorrect). I am puzzled by this bug since I understand R to be machine-independent.

My own conclusion, which may help Dr Kassambara, is that all three problems I report stem from some interaction between "label" and "position_dodge".

Sekhar Ramakrishnan

@sekharcu
Copy link
Author

sekharcu commented Jan 4, 2020

I have learned that the first bug I reported was actually due to the version of ggplot2 not being current on some of my machines. I noticed that, on the machines that had the problem, there was a warning when ggpubr was loaded:
Registered S3 methods overwritten by 'ggplot2':
method from
[.quosures rlang
c.quosures rlang
print.quosures rlang
Once I updated ggpubr, the "bug" went away. I am curious why a wrong version of ggplot2 should produce incorrect labels instead of an error message, but it's quite unimportant.

That still leaves the other two bugs, of which I am quite confident. But since no one has commented on this thread, I am closing this issue and will open a fresh issue on just those two bugs. Apologies to Dr Kassambara for an unnecessary issue report.

@sekharcu sekharcu closed this as completed Jan 4, 2020
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

1 participant