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

Label missing if identical #140

Open
jpquast opened this issue Jul 12, 2024 · 0 comments
Open

Label missing if identical #140

jpquast opened this issue Jul 12, 2024 · 0 comments

Comments

@jpquast
Copy link

jpquast commented Jul 12, 2024

Hi Constantin,
thank you very much for the great package!

I came across a bug when manually supplying values through a data frame. As you can see below, the label is not correctly added to the plot, if it is two times the same. This only happens if one manually supplies the start and end with a number. I have a facetted column plot with position = "dodge", so I need to supply it like this. In my case the label is the same since the significant levels between the two labels are the same as well.

Would be great if there is a fix or workaround for this bug.

Thanks a lot!

library(ggplot2)
#> Warning: package 'ggplot2' was built under R version 4.3.3
library(ggsignif)
#> Warning: package 'ggsignif' was built under R version 4.3.3
annotation_df <- data.frame(
  color = c("E", "E"),
  start = c(1, 2),
  end = c(2, 3),
  y = c(3.6, 4.7),
  label = c("Comp. 1", "Comp. 1")
)

annotation_df
#>   color start end   y   label
#> 1     E     1   2 3.6 Comp. 1
#> 2     E     2   3 4.7 Comp. 1
#>   color start       end   y   label
#> 1     E  Good Very Good 3.6 Comp. 1
#> 2     H  Fair      Good 4.7 Comp. 2

ggplot(diamonds, aes(x = cut, y = carat)) +
  geom_boxplot() +
  geom_signif(
    data = annotation_df,
    aes(xmin = start, xmax = end, annotations = label, y_position = y),
    textsize = 3, vjust = -0.2,
    manual = TRUE
  ) +
  facet_wrap(~color) +
  ylim(NA, 5.3)
#> Warning in geom_signif(data = annotation_df, aes(xmin = start, xmax = end, :
#> Ignoring unknown aesthetics: xmin, xmax, annotations, and y_position
#> Warning: The following aesthetics were dropped during statistical transformation: xmin,
#> xmax, and y_position.
#> ℹ This can happen when ggplot fails to infer the correct grouping structure in
#>   the data.
#> ℹ Did you forget to specify a `group` aesthetic or to convert a numerical
#>   variable into a factor?

Created on 2024-07-12 with reprex v2.1.0

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