重要的注释合并,而不是在R中单独显示。

问题描述 投票:0回答:1

当重要的注释相同时,它们就会合并,并在彼此之上绘制,而不是单独绘制。如何解决这个问题?

data <- tibble::tibble(
  value = c(1.63, 1.39,1.22,1.14,1.98,-1.34,-1.34,-1.29,-1.11,-1.23),
  variable = c("A", "B","C","D", "E", "F", "G", "H", "I" , "J"),
  type = c(rep("p",5),rep("n",5)))

ggplot(data, aes(x=variable, y=value) )+
  geom_bar(stat="identity", width = 0.8)+
  theme_classic() + scale_fill_grey()+
   geom_signif(stat="identity",
              data=data.frame(x=c(0.875, 1.875, 2.875, 3.875, 4.875, 5.875, 6.875, 7.875, 8.875, 9.875), xend=c(1.125, 2.125, 3.125, 4.125, 5.125, 6.125,7.125,8.125,9.125, 10.125),
                               y=c(0.1, 0.1, 0.1, 0.1, 0.1, -0.1, -0.1,-0.1,-0.1,-0.1), annotation=c("NS", "*", "***", "***","***",  "**", "*", "*", ".", "***")),
              aes(x=x,xend=xend, y=y, yend=y, annotation=annotation))

enter image description here

r ggplot2 geom-bar significance
1个回答
2
投票

如果你改变你的x值来匹配系数水平,似乎效果不错。

ggplot(data, aes(x = variable, y = value)) +
  geom_bar(stat = "identity", width = 0.8) +
  theme_classic() + 
  scale_fill_grey() +
   geom_signif(stat = "identity",
              data = data.frame(x = LETTERS[1:10], 
                                xend = 1:10 + 0.125,
                                y = rep(0.1, -0.1, each = 5), 
                                annotation = c("NS", "*", "***", "***","***",  "**", "*", "*", ".", "***")),
              aes(x = x, xend = xend, y = y, yend = y, annotation = annotation))

              aes(x=x,xend=xend, y=y, yend=y, annotation=annotation))

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.