const-ae/ggsignif

How to show significance annotations but remove lines between groups?

elcega opened this issue · 2 comments

I would like to remove the lines under the annotations. How can I do it?
Thanks,

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 = LETTERS[1:10],
xend = 1:10 + 0.125,
y = c(rep(-0.2,5),rep(0.1,5)),
annotation = c("NS", "", "", "","", "", "", "", ".", "***")),
aes(x = x, xend = xend, y = y, yend = y, annotation = annotation))

Hi elcega,

The easiest way to achieve this is to set lwd = 0:

library(ggplot2)
library(ggsignif)

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 = LETTERS[1:10],
                                xend = 1:10 + 0.125,
                                y = c(rep(-0.2,5),rep(0.1,5)),
                                annotation = c("NS", "", "", "","", "", "", "", ".", "***")),
              aes(x = x, xend = xend, y = y, yend = y, annotation = annotation), 
              lwd = 0)

Created on 2020-05-05 by the reprex package (v0.3.0)

Alternatively, you could also just use geom_text() directly if you don't need the line.

Best, Constantin

Perfect, thanks!