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

pairwise display disappears when limiting y-axis #966

Open
debbiemaycry opened this issue Oct 22, 2024 · 4 comments
Open

pairwise display disappears when limiting y-axis #966

debbiemaycry opened this issue Oct 22, 2024 · 4 comments
Labels
question ❓ Further information is requested

Comments

@debbiemaycry
Copy link

Hi! Terribly sorry if this has already been asked or has a simple solution. I didn't find it in the issues section. ggbetweenstats seems to add values to the y-axis even beyond the limit of the variable. I added code to limit the y-axis values, however, that then makes the pairwise comparisons above disappear. I already tried 3 ways to limit the y-axis and they all make it disappear. Do you have a solution for that? Thanks in advance.

My code:

ggbetweenstats( data = ds3_clean_90, x = condition_concept_fact, y = Schuldfaehigkeit_um, type = "parametric", # ANOVA or Kruskal-Wallis var.equal = TRUE, # ANOVA or Welch ANOVA plot.type = "box", pairwise.comparisons = TRUE, pairwise.display = "significant", centrality.plotting = TRUE, centrality.label.args = list(size = 3, nudge_x = 0.4, nudge_y = 0.2, segment.linetype = 4, min.segment.length = 0), bf.message = FALSE, xlab = "Conceptualization", ylab = "Culpability", p.adjust.method = "bonferroni" ) + ggplot2::scale_y_continuous( limits = (c(0, 5)))

Plot with no y-axis limit
image

Plot once y-axis limit is added
image

@IndrajeetPatil
Copy link
Owner

The only way you can have your cake (display pairwise comparisons) and eat it too (and not display axes labels for values that are not observed in the data) is to hide axes labels:

library(ggstatsplot)
library(ggplot2)

max(mtcars$wt)
#> [1] 5.424
ggbetweenstats(mtcars, cyl, wt) + scale_y_continuous(labels = c(0:5, NA))
#> Scale for y is already present.
#> Adding another scale for y, which will replace the existing scale.

Created on 2024-10-22 with reprex v2.1.1

@IndrajeetPatil IndrajeetPatil added the question ❓ Further information is requested label Oct 22, 2024
@debbiemaycry
Copy link
Author

Thanks so much for the quick reply! That code does work perfectly with the cars data, but for some reason not with mine. Might you have an idea of the reason? I checked and both variables (cyl and Culpability) are numeric.

image

@debbiemaycry
Copy link
Author

debbiemaycry commented Oct 29, 2024

Hi again! Just popping by quickly to let you know that I was looking at your solution before and unfortunately it completely shifts the graph up so that the datapoints are no longer where they're supposed to be (the mean of the group with 4 cylinders is 2.29, but it appears in 1.29 in the y-scale).

What kinda worked (there is still graph there, but at least no number or anything to mark it) in my code was just adding a blank space:

+ scale_y_continuous(labels = c(1:5, ""))

But trying this solution out in the mtcars data shows the same problem of shifting the y-axis upwards. I tried the following code, but then I reproduced the same issue as with my graph (that it shows the NA).

ggbetweenstats(mtcars, cyl, wt)+ scale_y_continuous(labels = c(0:5, NA), breaks = seq(0, 6, 1), limits = c(0, 6))

image

@seanso95
Copy link

seanso95 commented Dec 4, 2024

Hello! I think you can probably just set your range of labels using the breaks argument in scale_y_continuous to the range where you actually want axis labels. This isn't an adaptive solution as it depends on the min/max range of the data, plus some allowance on the plot to have space for the plotting of the statistics visuals, but you could try: scale_y_continuous(limits = c(0, 6), breaks = seq(1, 5, 1)).

When you set labels in scale_y_continuous() it actually just passes in text to "rename" the labels. You can see this by doing: ggbetweenstats(mtcars, cyl, wt) + scale_y_continuous(labels = c(10:15, NA))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question ❓ Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants