0

我想使用 geom_signif 函数在我的组比较之上添加第二个比较。我有 3 个子组,我正在比较 (C4) 的各个子组。我希望我的最终图看起来像这样(附上)。

在此处输入图像描述

tgc4 < - structure(list(Condition = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 
2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L), .Label = c("CEN", "IPS", 
"CTL"), class = "factor"), Electrode = structure(c(1L, 2L, 3L, 
4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L), .Label = c("C4", 
"CP2", "CP6", "P4", "P8"), class = "factor"), N = c(24, 24, 24, 
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24), measurement = c(0.475900166666667, 
0.733097333333333, 1.089481625, 2.01497575, 2.16174375, 0.434101083333333, 
0.701428416666667, 1.01162383333333, 1.92838604166667, 2.05454458333333, 
0.524649375, 0.7666545, 1.10670179166667, 2.021725125, 2.14652179166667
), sd = c(0.690171324253539, 1.06910371259459, 1.68860310942122, 
3.4014857218051, 4.43699113062584, 0.683641055049957, 1.01566311510833, 
1.65013550853766, 3.32008309477149, 4.36699670813656, 0.721378974999592, 
1.08818214299657, 1.7267893116772, 3.42645198458195, 4.41596190187272
), se = c(0.140880631626844, 0.218229881497655, 0.344684666346589, 
0.694325365482085, 0.905697021940661, 0.139547646007528, 0.207321365215089, 
0.336832500197108, 0.677709123819216, 0.891409470279034, 0.147250866660079, 
0.222124249795826, 0.352479392241743, 0.699421582531046, 0.901404448596543
), ci = c(0.291433790775513, 0.451442905180972, 0.713034558232622, 
1.4363214514115, 1.87357703717142, 0.288676299929537, 0.428876919954661, 
0.696791114969224, 1.40194813663905, 1.84402098469234, 0.304611625957172, 
0.459499019798758, 0.729159177276763, 1.44686377959418, 1.86469717265482
)), row.names = c(NA, -15L), class = "data.frame")
library(ggplot2)
library(ggthemes)
library(ggsignif)

p4 <- ggplot(tgc4, aes(fill=Condition, x = Electrode, y = measurement)) + 
  geom_errorbar(aes(ymin=measurement-se, ymax=measurement+se), width=.7,position=pd) + 
  scale_fill_manual(name = "Condition", 
                    values=c("red", "blue", "black")) +
  geom_bar(stat = "identity", width = 0.7, color = "black", position = pd)  + theme_bw() + ylim(0,3.5) + theme(
                      axis.text.x = element_text(size = 16,face="bold"),
                      axis.text.y = element_text(size = 16, face = "bold"),
                      axis.title.y = element_text(vjust= 1.8, size = 20),
                      axis.title.x = element_text(vjust= -0.5, size = 18),
                      axis.title = element_text(face = "bold")) + xlab("Electrode") + ylab("Change in alpha activity (\U00B5V)") #+ theme(legend.position=c(.1,.1))


p4  + theme(aspect.ratio = 5/5) + theme(legend.text=element_text(size=14), legend.title=element_text(size=16)) 

p4 + geom_signif(
  y_position = c(0.8, 1.1, 1.6, 2.85, 3.2), xmin = c(1, 2, 3, 4, 5), xmax = c(1.4, 2.4, 3.4, 4.4,5.4),
  annotation = c("***", "*", "*", "ns", "ns"), tip_length = 0.005, textsize = 7, size = 1
)  
4

1 回答 1

0

只需在参数中添加附加值geom_signif

p4 <- ggplot(tgc4, aes(fill=Condition, x = Electrode, y = measurement)) + 
  geom_errorbar(aes(ymin=measurement-se, ymax=measurement+se), width=.7,position="dodge") + 
  scale_fill_manual(name = "Condition", 
                    values=c("red", "blue", "black")) +
  geom_bar(stat = "identity", width = 0.7, color = "black", position = "dodge")  + theme_bw() + ylim(0,3.5) + theme(
    axis.text.x = element_text(size = 16,face="bold"),
    axis.text.y = element_text(size = 16, face = "bold"),
    axis.title.y = element_text(vjust= 1.8, size = 20),
    axis.title.x = element_text(vjust= -0.5, size = 18),
    axis.title = element_text(face = "bold")) + xlab("Electrode") + ylab("Change in alpha activity (\U00B5V)") #+ theme(legend.position=c(.1,.1))


p4  + theme(aspect.ratio = 5/5) + theme(legend.text=element_text(size=14), legend.title=element_text(size=16)) 

p4 + geom_signif(
  y_position = c(1.2, 0.8, 1.1, 1.6, 2.85, 3.2), xmin = c(0.6, 1, 2, 3, 4, 5), xmax = c(1, 1.4, 2.4, 3.4, 4.4,5.4),
  annotation = c("**", "***", "*", "*", "ns", "ns"), tip_length = 0.005, textsize = 7, size = 1
)  

在此处输入图像描述

于 2021-10-01T05:31:59.310 回答