const-ae/ggsignif

Example on repo doesn't work with fill in aes

BJWiley233 opened this issue · 2 comments

If you change the advanced example on the repo markdown to color by cut it doesn't work

ggplot(diamonds, aes(x = cut, y = carat, fill=cut)) +
  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)

You get this error

Aesthetics must be valid data columns. Problematic aesthetic(s): fill = cut. 
Did you mistype the name of a data column or forget to add after_stat()?

So the only way to do it is without aes in the call to geom_signif

You will have to pass that aesthetic actually to geom_boxplot:

library(ggplot2)
library(ggsignif)

annotation_df <- data.frame(
  color = c("E", "H"),
  start = c("Good", "Fair"),
  end = c("Very Good", "Good"),
  y = c(3.6, 4.7),
  label = c("Comp. 1", "Comp. 2")
)

ggplot(diamonds, aes(x = cut, y = carat)) +
  geom_boxplot(aes(fill = cut)) +
  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: Ignoring unknown aesthetics: xmin, xmax, annotations, y_position

Created on 2021-01-29 by the reprex package (v1.0.0)

Cool thank you!