向闪避条形图添加显着性条

Add significance bars to dodged bar plot

我有这样的数据:

     reading condition   time
       <dbl>     <chr> <fctr>
1  0.0603376         A      4
2  0.0000000         A      4
3  0.0576497         A      4
4 11.4080000         B      4
5 11.0495000         B      4
6 14.0659000         B      4
...

我想使用 ggplot2 绘制一个条形图,其中显着性条横跨带有自定义注释的闪避列。我正在使用 ggsignif 扩展包。文档中的示例有效:

ggplot(mpg, aes(class, hwy)) +
  geom_boxplot() +
  geom_signif(annotations = c("First", "Second"),
              y_position = c(30, 40), xmin=c(4,1), xmax=c(5,3))

但是当我用我的数据尝试它时,它没有。我试过调整参数但不明白为什么它不起作用。有人可以帮忙吗?

df %>% 
ggplot(aes(time, reading,  fill = condition, group = condition)) +
  geom_bar(stat = "summary", fun.y = "mean", position = position_dodge(width = 0.5), width = 0.5) +
  geom_point(position = position_dodge(width = 0.5)) +
  geom_signif(annotations = c("First", "Second"),
              y_position = c(4, 12), xmin=c(1.5,2.5), xmax=c(2.5,3.5))

数据:

df <- structure(list(reading = c(0.0603376, 0, 0.0576497, 11.408, 11.0495, 
14.0659, 0, 0, 0, 1.00595, 0.862592, 1.93105, 0, 0, 0, 0.0726477, 
0.0778178, 0), condition = c("A", "A", "A", "B", "B", "B", "B", 
"B", "B", "B", "B", "B", "A", "A", "A", "A", "A", "A"), time = structure(c(3L, 
3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 
2L), .Label = c("0", "2", "4"), class = "factor")), .Names = c("reading", 
"condition", "time"), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -18L))

只需从代码的第一行删除 group = condition

df %>% 
  ggplot(aes(time, reading,  fill = condition)) +
  geom_bar(stat = "summary", fun.y = "mean", position = position_dodge(width = 0.5), width = 0.5) +
  geom_point(position = position_dodge(width = 0.5)) +
  geom_signif(annotations = c("First", "Second"),
          y_position = c(4, 12), xmin=c(1.5,2.5), xmax=c(2.5,3.5))