const-ae / ggsignif

Easily add significance brackets to your ggplots
https://const-ae.github.io/ggsignif/
GNU General Public License v3.0
593 stars 43 forks source link

Manual vertical brackets do not work: "arguments imply differing number of rows" #115

Open bersbersbers opened 2 years ago

bersbersbers commented 2 years ago

I am trying to manually annotate a Kaplan-Meier-Plot with vertical significance brackets, and I am failing.

The reasons seems to be the orientation: the following horizontal example works fine, while the vertical does not print the brackets at all:

image

image

df <- data.frame(
  x = 1:4, y = c(1, 1, 1, 5)
)

df_signif <- data.frame(
  xmin = c(1, 3),
  xmax = c(3, 4),
  y_position = c(2, 6),
  annotations = c("NS", "***")
)

ggplot(df, aes(x = x, y = y)) +
  geom_point() +
  ggsignif::geom_signif(
    mapping = aes(
      xmin = xmin,
      xmax = xmax,
      y_position = y_position,
      annotations = annotations,
    ),
    data = df_signif,
    manual = TRUE,
  )

ggplot(df, aes(x = y, y = x)) + # note the reversed coordinates!
  geom_point() +
  ggsignif::geom_signif(
    mapping = aes(
      xmin = xmin,
      xmax = xmax,
      y_position = y_position,
      annotations = annotations,
    ),
    data = df_signif,
    manual = TRUE,
    orientation = "y", # note the orientation!
  )
bersbersbers commented 2 years ago

Functionally related: kassambara/ggpubr#456