Label missing if identical
Opened this issue · 0 comments
jpquast commented
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