0

在此处输入图像描述我想使用 geom_signif 在我的条形图中创建一个重要的层,就像我附加的条形图一样,我只想比较工作区(即 MID、NMC 和 CML)内测试前后的差异。例如,仅比较 MID 的前后测试,对 NMC 和 CML 进行相同的比较。我尝试过,但看起来我做错了什么

tgc <- structure(list(Workspace = structure(c(1L, 1L, 2L, 2L, 3L, 3L
), .Label = c("MID", "NMC", "CML"), class = "factor"), Time = structure(c(1L, 
2L, 1L, 2L, 1L, 2L), .Label = c("Pretest", "Posttest"), class = "factor"), 
    N = c(24, 24, 24, 24, 24, 24), EndpointError = c(2.85950807291667, 
    0.8204433125, 2.86077222916667, 0.937923947916667, 3.26658860416667, 
    1.12849661458333), sd = c(0.797084414369766, 0.601614858238859, 
    0.624571419971566, 0.88787261995896, 0.800703365914924, 1.04237568245573
    ), se = c(0.162704174760923, 0.122804118696837, 0.12749010723799, 
    0.181236239623958, 0.163442890151714, 0.212774045191827), 
    ci = c(0.336579229366135, 0.254039674733015, 0.263733380591008, 
    0.374915726381832, 0.338107378581228, 0.440156647885719)), row.names = c(NA, 
-6L), class = "data.frame")
p <- ggplot(tgc, aes(x = Workspace, y = EndpointError, fill = Time)) + 
  geom_errorbar(aes(ymin=EndpointError-se, ymax=EndpointError+se), position = position_dodge(0.5), width=.1) +
  geom_bar(aes(fill = Time), stat = "identity", width = 0.5, color = "black", position='dodge') + theme_bw() + theme(
    axis.text.x = element_text(size = 12,face="bold"),#, angle = 10, hjust = .5, vjust = .5),
    axis.text.y = element_text(size = 12, face = "bold"),
    axis.title.y = element_text(vjust= 1.8, size = 14),
    axis.title.x = element_text(vjust= -0.5, size = 14),
    axis.title = element_text(face = "bold")) + xlab("Workspace") + ylab("Endpoint error (cm)") + theme(legend.position="right")
p + theme(aspect.ratio = 3/2)


p + 
  geom_signif(comparisons = list(c("Time", "Workspace")), 
              map_signif_level = TRUE)[![enter image description here][1]][1]
4

1 回答 1

0

这个答案可能对您的问题有所帮助https://github.com/kassambara/ggpubr/issues/100#issuecomment-407204663

您的代码可以如下更新。

p <- ggplot(tgc, aes(x = Time, y = EndpointError, fill = Time)) + 
  geom_errorbar(aes(ymin=EndpointError-se, ymax=EndpointError+se), position = position_dodge(0.5), width=.1) +
  geom_bar(aes(fill = Time), stat = "identity", width = 0.5, color = "black", position='dodge') + theme_bw() + facet_wrap(~Workspace) + theme(
    axis.text.x = element_text(size = 12,face="bold"),#, angle = 10, hjust = .5, vjust = .5),
    axis.text.y = element_text(size = 12, face = "bold"),
    axis.title.y = element_text(vjust= 1.8, size = 14),
    axis.title.x = element_text(vjust= -0.5, size = 14),
    axis.title = element_text(face = "bold")) + xlab("Workspace") + ylab("Endpoint error (cm)") + theme(legend.position="right")
p + theme(aspect.ratio = 3/2)


p + 
  geom_signif(comparisons = list(c("Pretest", "Posttest")), map_signif_level = TRUE)

于 2021-03-01T07:30:42.893 回答