在ggplot2 barplot上手动绘制子组之间的重要性关系

我一直在尝试使用ggplot2ggsignifggpubr条形图上为一组子集手工绘制标记的重要性条,但运气不佳。数据类似于以下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",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")

在ggplot2 barplot上手动绘制子组之间的重要性关系

我要手动指定重要性标签的地方,例如在“飞行”的“巴西/厄瓜多尔”和“跳跃”的厄瓜多尔/秘鲁之间。是否有人知道如何正确处理此类数据,例如使用{{1 }}?还有一种方法可以按名称引用每个条形,而不是尝试确定其x轴位置?

loveldj13ldj 回答:在ggplot2 barplot上手动绘制子组之间的重要性关系

如果您知道要在哪个条形图上添加重要性标签,则可以执行以下操作:

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)

enter image description here

它回答了您的问题吗?

本文链接:https://www.f2er.com/2515795.html

大家都在问