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

Annotations disappear when setting a high y_position #48

Open
arnssino opened this issue Sep 13, 2018 · 6 comments
Open

Annotations disappear when setting a high y_position #48

arnssino opened this issue Sep 13, 2018 · 6 comments

Comments

@arnssino
Copy link

arnssino commented Sep 13, 2018

Hi,

I am using this wonderful package, which I found very useful to my work, and I am faced with a little problem here.
I am trying to do a violin plot using Seurat package.

library(Seurat)
library(ggsignif)
fig <- VlnPlot(object = pbmc_small, features.plot = 'PC1', do.return = TRUE)
fig  + geom_signif(xmin = 3, xmax = 4, y_position = 8 , annotations="**")

plot1

It needs a bit of refinement because the annotation overlaps other part of the plot, so I set y_position from 8 to 9

library(Seurat)
library(ggsignif)
fig <- VlnPlot(object = pbmc_small, features.plot = 'PC1', do.return = TRUE) +
coord_cartesian(ylim = c(-4,15))
fig  + geom_signif(xmin = 3, xmax = 4, y_position = 9 , annotations="**")

plot2

However, the annotation disappeared, and I do not know how to fix this.
Thank you very much in advance!

@const-ae
Copy link
Owner

Sorry, without a minimal reproducible example I cannot help you. The trick usually is to manually increase the domain of the y-axis (ylim(-5, 20)) to make sure that all the annotations are displayed.

@bbarker505
Copy link

bbarker505 commented Jun 27, 2019

Hi const-ae,

I had the same issue as arnssino. I really like the 'ggsignif' package, but I would highly recommend that there be a way to move the annotations (labels) for the significance bars and symbols. In my instance, my original data had some extreme outliers, which I did not want to show in my geom_boxplot. So, I removed the extreme outliers for visual purposes. The big issue is that I am unable to correctly display the results of the 'geom_signif' function from the "original data", because the function still wants to put the annotations/labels way up high on the y-axis of my geom_boxplot of the "outliers removed" data.

Fortunately the 'geom_signif' results from the "outliers removed" data were the same on the "original" data (significance level), so it was not an issue. However, if they were different then that would be an issue.

Just a thought.

Best,
Brittany

@const-ae
Copy link
Owner

const-ae commented Jul 1, 2019

Hi Brittany,

I have to admit, I am still not quite sure that I understand what this issue is about.

I made a small reproducible example, where I use ylim(ymin, ymax) to cutoff some values and the annotation diseappears. Is that the problem that you are describing?

library(ggplot2)
library(ggsignif)


ggplot(mtcars, aes(x=as.factor(cyl), y=mpg)) +
  geom_boxplot() +
  geom_signif(comparison = list(c("4", "6")),
              y_position = 40) +
  coord_cartesian(ylim = c(0, 50))
#> Warning in wilcox.test.default(c(22.8, 24.4, 22.8, 32.4, 30.4, 33.9,
#> 21.5, : cannot compute exact p-value with ties

ggplot(mtcars, aes(x=as.factor(cyl), y=mpg)) +
  geom_boxplot() +
  geom_signif(comparison = list(c("4", "6")),
              y_position = 40) +
  coord_cartesian(ylim = c(0, 50)) +
  ylim(0, 25)
#> Warning: Removed 6 rows containing non-finite values (stat_boxplot).
#> Warning: Removed 6 rows containing non-finite values (stat_signif).
#> Warning in wilcox.test.default(c(22.8, 24.4, 22.8, NA, NA, NA, 21.5, NA, :
#> cannot compute exact p-value with ties
#> Warning: Removed 3 rows containing missing values (geom_signif).

Created on 2019-07-01 by the reprex package (v0.2.1)

@bbarker505
Copy link

Hello,
That is similar to what I was talking about. I tried creating a small reproducible example of my exact problem and it was taking too long - sorry. But your example is similar enough. It would just be really great to have a way to adjust the p-value labels so they're not cut off when adjusting the y-axis limits.
Thanks,
Brittany

@const-ae
Copy link
Owner

Hi Brittany,
no problem. I agree that it would be nice to have that feature, the problem is that removing elements outside of the ylim() is pretty deeply engrained in ggplot, so I don't think that there is an easy fix from my side. But what I might be able to do, is to provide a helpful warning that tells the user that the annotation was just cut off and that they should rather use coord_cartesian(ylim=c(...)) or filter the data before calling ggplot(). Unfortunately, I am fairly busy right now, so I cannot promise that I will get around to address the issue soon.
Best, Constantin

@mschubert
Copy link

mschubert commented Dec 21, 2022

I'm running into a similar issue here, which I think is best split in two parts, taking the original reprex as a starting point (ggsignif=0.6.4):

library(ggplot2)
library(ggsignif)

ggplot(mtcars, aes(x=as.factor(cyl), y=mpg)) +
  geom_boxplot() +
  geom_signif(comparison = list(c("4", "6")),
              y_position = 40) +
  coord_cartesian(ylim = c(0, 50))
  1. Your y_position does not longer seem to be respected

Note how the bar below is no longer at 40, but above that (and the end of tips also end above 40). I'm not sure if this is intended.

image

  1. If I now add one extreme point to the data set, the comparison disappears
library(ggplot2)
library(ggsignif)
mtcars$mpg[mtcars$cyl=="4"][1] = 1000

ggplot(mtcars, aes(x=as.factor(cyl), y=mpg)) +
  geom_boxplot() +
  geom_signif(comparison = list(c("4", "6")),
              y_position = 40) +
  coord_cartesian(ylim = c(0, 50)) # removing this line draws the comparison higher than y_position

image

If I then set the limits much above the requested y_position, the comparison is shown again:

library(ggplot2)
library(ggsignif)
mtcars$mpg[mtcars$cyl=="4"][1] = 1000

ggplot(mtcars, aes(x=as.factor(cyl), y=mpg)) +
  geom_boxplot() +
  geom_signif(comparison = list(c("4", "6")),
              y_position = 40) +
  coord_cartesian(ylim = c(0, 100))

image

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

No branches or pull requests

5 participants