【发布时间】:2019-07-15 09:15:53
【问题描述】:
这是我的数据的一个发明示例:
x <- c("Control", "Case", "Case", "Case", "Control", "Control", "Control", "Case", "Case", "Case")
y <- c("Dead", "Dead", "Dead", "Alive", "Alive", "Dead", "Dead", "Dead", "Alive", "Dead")
我试图以条形图的形式表示这些数据,然后指出两个实验组(病例和对照组)之间存活和死亡患者比例的统计显着差异。我进行了 Pearson 卡方检验,p 值为 4.674e-06。
这是我的情节代码:
library(ggsignif)
ggplot(data, aes(x = data$x,
fill = data$y)) +
geom_bar(aes(y = stat(count/sum(count))), position = position_dodge(0.9)) +
theme(plot.title = element_text(hjust = 0.5)) +
ylim(c(0, 0.4)) +
labs(x = NULL, y = "Proportion", fill = NULL) +
scale_x_discrete(labels = c("Control", "Case")) +
geom_signif(comparisons = list(c("Control", "Case"), map_signif_level = TRUE))
然后我得到:
Error: stat_signif requires the following missing aesthetics: y
谁能告诉我为什么会这样,我该如何解决?
谢谢
【问题讨论】:
-
您是否尝试在
ggplot()中指定y而不仅仅是在geom_bar()中?除了在aes()中使用裸列名称而不是data$x等。 -
嗯。除了 Markus 的评论,
geom_signif似乎无法与geom_bar一起使用。
标签: r ggplot2 bar-chart p-value