0

enter image description hereI want to use geom_signif to create a significant layer in my barplot like the bar graph I have attached, I just want to compare the difference from pre to post-test within a workspace (i.e, MID, NMC, and CML). For example, just comparing pre and post-test for MID, do the same comparison for NMC and CML. I attempted it but looks like I am doing something wrong

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]

1 Answers1

0

This answer might be helpful to your question https://github.com/kassambara/ggpubr/issues/100#issuecomment-407204663

Your code can be updated as below.

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)

lil_barnacle
  • 168
  • 7