这是我的数据的发明示例:
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
谁能告诉我为什么会发生这种情况以及如何解决它?
Thanks