Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add math/subscript in geom_bracket in ggplot2?

Tags:

r

ggplot2

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

like image 912
Guilherme Parreira Avatar asked Oct 23 '20 12:10

Guilherme Parreira


1 Answers

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

like image 118
Ritchie Sacramento Avatar answered Oct 31 '22 20:10

Ritchie Sacramento