7

I there!

I want to include a label with subscript in geom_bracket in ggplot2. I tried in different ways, but no one worked (attempts in the comments):

library(ggplot2)
ggplot(data = mtcars, aes(x = vs, y = disp)) +
  geom_point() +
  geom_bracket(xmin = .25, xmax = .75, y.position = 250
               ,label = paste0("p_b<", format(0.06, nsmall = 3))
               # ,label = paste0(expression(p[b]), "<", format(0.06, nsmall = 3))
               # ,label = TeX(paste0("p_b<", format(0.06, nsmall = 3)))
               )

What I got:

enter image description here

Subscript does not work.

Thanks

zx8754
  • 52,746
  • 12
  • 114
  • 209

1 Answers1

5

geom_bracket() (which is from ggpubr not ggplot2) uses an argument to specify whether the label is an expression or text, so you can do:

library(ggplot2)
library(ggpubr)

ggplot(data = mtcars, aes(x = vs, y = disp)) +
  geom_point() +
  geom_bracket(xmin = .25, xmax = .75, y.position = 250,
               label = "p[b] < 0.06", type = "expression")

enter image description here

Ritchie Sacramento
  • 29,890
  • 4
  • 48
  • 56