I would like to use the expression functionality within ggpubr to have both the ability to italicise my APA test statistics within text of a between groups comparison using geom_bracket within ggpubr.
My problem is that I need to remove the leading 0 that is produced, but this appears to be rendered not within the string (hence the second example where I show gsub() can't just pull it out.
library(ggpubr)
library(ggplot2)
# Example close to what I currently have in code with leading 0 in-front of p value
ggboxplot(df, x = "dose", y = "len") +
geom_bracket(
xmin = "0.5", xmax = "1", y.position = 30,
label = "list(~italic(t)(666)==6.66,~italic(p) < .05)",
type = "expression",
tip.length = c(0.2, 0.02)
)
# what i thought would work to use `gsub()` to remove what I don't want
ggboxplot(df, x = "dose", y = "len") +
geom_bracket(
xmin = "0.5", xmax = "1", y.position = 30,
label = gsub(pattern = "p","q", "list(~italic(t)(666)==6.66,~italic(p) < .05)"),
type = "expression",
tip.length = c(0.2, 0.02)
)
# but if you remove the zeros, they only come out of the text, not the leading 0 that is added
ggboxplot(df, x = "dose", y = "len") +
geom_bracket(
xmin = "0.5", xmax = "1", y.position = 30,
label = gsub(pattern = "0", "", "list(~italic(t)(666)==6.66,~italic(p) < .05)"),
type = "expression",
tip.length = c(0.2, 0.02)
)
Is there a way to either:
- Have the ability to write both numbers, letters, and italics within an expression? I have tried this with using the "text" argument then using
italics()but have not been able to get this to work. Could just be doing something silly after getting very frustrated with it. - Remove the leading 0 that is inserted using plotmath?
Either way, would be interested to know why the 0 is inserted anyway.
