在 ggplot2 条形图上手动绘制子组之间的显着性关系
Manually plotting significance relations between sub-groups on ggplot2 barplot
我一直在尝试使用 ggsignif
或 ggpubr
在 ggplot2
条形图上为一组子集绘制手动标记的显着性条,但运气不佳。数据类似于以下 MWE:
set.seed(3)
## create data
df <- data.frame(activity = rep(c("Flying", "Jumping"), 3),
mean = rep(rnorm(6, 50, 25)),
group = c(rep("Ecuador", 2),
rep("Peru", 2),
rep("Brazil", 2)))
## plot it
ggplot(df, aes(x = activity, y = mean, fill = group)) +
geom_bar(position = position_dodge(0.9), stat = "identity",
width = 0.9, colour = "black", size = 0.1) +
xlab("Activity") + ylab("Mean")
在我想手动指定重要性标签的地方,比如在 "Flying" 上的 Brazil/Ecuador" 和 "Jumping" 上的 Ecuador/Peru 之间。有谁知道如何正确处理这种数据,例如 ggsignif
?有没有办法按名称引用每个柱,而不是尝试计算出它的 x 轴位置?
如果您知道要在哪个条形图上添加重要性标签,您可以这样做:
library(ggsignif)
library(ggplot2)
ggplot(df, aes(x = activity, y = mean, fill = group)) +
geom_bar(position = position_dodge(0.9), stat = "identity",
width = 0.9, colour = "black", size = 0.1) +
xlab("Activity") + ylab("Mean")+
geom_signif(y_position = c(60,50), xmin = c(0.7,2), xmax = c(1,2.3),
annotation=c("**", "***"), tip_length=0)
它回答了你的问题吗?
我一直在尝试使用 ggsignif
或 ggpubr
在 ggplot2
条形图上为一组子集绘制手动标记的显着性条,但运气不佳。数据类似于以下 MWE:
set.seed(3)
## create data
df <- data.frame(activity = rep(c("Flying", "Jumping"), 3),
mean = rep(rnorm(6, 50, 25)),
group = c(rep("Ecuador", 2),
rep("Peru", 2),
rep("Brazil", 2)))
## plot it
ggplot(df, aes(x = activity, y = mean, fill = group)) +
geom_bar(position = position_dodge(0.9), stat = "identity",
width = 0.9, colour = "black", size = 0.1) +
xlab("Activity") + ylab("Mean")
ggsignif
?有没有办法按名称引用每个柱,而不是尝试计算出它的 x 轴位置?
如果您知道要在哪个条形图上添加重要性标签,您可以这样做:
library(ggsignif)
library(ggplot2)
ggplot(df, aes(x = activity, y = mean, fill = group)) +
geom_bar(position = position_dodge(0.9), stat = "identity",
width = 0.9, colour = "black", size = 0.1) +
xlab("Activity") + ylab("Mean")+
geom_signif(y_position = c(60,50), xmin = c(0.7,2), xmax = c(1,2.3),
annotation=c("**", "***"), tip_length=0)
它回答了你的问题吗?