添加显着的酒吧躲闪条形图

By simon at 2018-02-07 • 0人收藏 • 43人看过

我有这样的数据:

     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和重要条来绘制条形图 AC罗斯躲闪了自定义注释的列。我正在使用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))
但是当我用我的数据尝试它没有。我已经尝试调整 参数,但不明白为什么它不工作。 C有人帮忙吗?
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))

1 个回复 | 最后更新于 2018-02-07
2018-02-07   #1

只需从代码的第一行删除group = condition即可: ![输入图片说明 这里](https://i.stack.imgur.com/syrgh.png)

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))

登录后方可回帖

Loading...