向条形图添加星号时,如何移动R中的条形图?

向条形图添加星号时,如何移动R中的条形图?,r,ggplot2,significance,R,Ggplot2,Significance,我在R中创建了一个条形图,现在我尝试将显著的差异添加到条形图中 我试过使用ggsignif包中的geom\u signif,以及ggpubr包中的stat\u compare\u means(基于这些建议/示例:或) 我只能在使用geom_signif时添加显著性水平,并选择如中所示的参数 这是我想要得到的一个例子: 这就是我得到的: 因此,当我想要添加星号时,它会移动条形图中的条形。我不知道如何改变它 这是我写的一部分: bargraph = ggplot(dataPlotROI, aes

我在R中创建了一个条形图,现在我尝试将显著的差异添加到条形图中

我试过使用ggsignif包中的
geom\u signif
,以及ggpubr包中的
stat\u compare\u means
(基于这些建议/示例:或)

我只能在使用
geom_signif
时添加显著性水平,并选择如中所示的参数

这是我想要得到的一个例子:

这就是我得到的:

因此,当我想要添加星号时,它会移动条形图中的条形。我不知道如何改变它

这是我写的一部分:

bargraph = ggplot(dataPlotROI, aes(x = ROI, y=mean, fill = Group))

bargraph + 
  geom_bar(position = position_dodge(.5), width = 0.5, stat = "identity") +
  geom_errorbar(position = position_dodge(width = 0.5), width = .2, 
                aes(ymin = mean-SEM, ymax = mean+SEM)) +
  geom_signif(y_position = c(4.5,10,10), xmin=c(0.85,0.85,4.3), xmax = c(5,4,7.45),
              annotation=c("***"), tip_length = 0.03, inherit.aes = TRUE) +
  facet_grid(.~ROI, space= "free_x", scales = "free_x", switch = "x")
这是来自
dput(dataPlotROI)
的输出:

>Dput-Dput
组ROI平均SD扫描电镜
1 1标段2.561758 1.151924 0.1200964
2.1 MO 7.508257 4.305644 0.4488944
3 1 ROT 3.342909 2.015815 0.2101633
4 2标段2.417504 1.114049 0.1161476
5.2 MO 6.903100 3.352766 0.3495500
6 2 ROT 3.030407 1.237868 0.1290567
有人知道我做错了什么,以及我如何纠正它吗


谢谢

我不认为
geom_signif
应该跨越各个方面,但在你的情况下,我看不出对方面有任何真正的需求。查看以下各项是否适用于您:

ggplot(dataPlotROI,
       aes(x = ROI, y = mean, fill = Group)) +

  # geom_col is equivalent to geom_bar(stat = "identity")
  geom_col(position = position_dodge(0.5), width = 0.5) +

  geom_errorbar(position = position_dodge(0.5), width = 0.2,
                aes(ymin = mean - SEM, ymax = mean + SEM)) +

  # xmin / xmax positions should match the x-axis labels' positions
  geom_signif(y_position = c(4.5, 10, 10),
              xmin = c(1, 1, 2.05),
              xmax = c(3, 1.95, 3),
              annotation = "***",
              tip_length = 0.03)

你能在你的问题中包含来自
dput(dataPlotROI)
的输出吗?@Z.Lin我为这个图添加了输出确实不需要刻面。这正是我想要的,谢谢!也许还有一个问题,你认为/知道是否也可以调整星号的位置?我设法改变了星号的大小,但我似乎找不到改变星号的可能性(例如,现在在中间条中的星号,因为我的颜色较暗,很难看到星号)。我补充说:<代码>注释(“text”),标签=“***”,x=1.5,y=4.2,族=“寒武系”。,color=“black”,size=7.5)这样就行了。
ggplot(dataPlotROI,
       aes(x = ROI, y = mean, fill = Group)) +

  # geom_col is equivalent to geom_bar(stat = "identity")
  geom_col(position = position_dodge(0.5), width = 0.5) +

  geom_errorbar(position = position_dodge(0.5), width = 0.2,
                aes(ymin = mean - SEM, ymax = mean + SEM)) +

  # xmin / xmax positions should match the x-axis labels' positions
  geom_signif(y_position = c(4.5, 10, 10),
              xmin = c(1, 1, 2.05),
              xmax = c(3, 1.95, 3),
              annotation = "***",
              tip_length = 0.03)