I want to be able to pass an argument from a function into a label on a ggplot
graph and for that label to be in bold. Unicode won't work because many unicode symbols don't render to pdf. Plotmath expressions can be split apart in paste()
, which makes them ideal for this sort of work, however I can't work out how to get the Plotmath bold(x)
expression to bold the entire compiled string.
For example, this code...
y <- 5
(g <- ggplot(data.frame(x = rnorm(100,0,1)), aes(x)) +
geom_histogram(bins = 100, fill = "skyblue") +
annotate("text", x = 1.5, y = 4, label = paste0("bold(x<=", y, "^{2})"), parse = T))
...yields...
As you can see the special character (less than or equal to) has come out fine. However the problem is that the x is bolded but not the rest of the string. How do I bold the entire string in a way that still allows me to pass the outside object y
into the string?