Superscripted star in geom_label

Viewed 628

I want to plot a superscripted star in a geom_label from a data frame string, but can't find a solution.

A minimum working example would be

library(ggplot2)
df <- data.frame(x = 1, y = 1, l = "P^2")
# the real data.frame has more observations with other expressions as well

ggplot(df, aes(x = x, y = y, label = l)) + 
  geom_label(parse = T)

But instead of having P^2 I want to display P^*. However, neither "P*", "P^*", latex2exp::TeX("P^\\star", output = "character"), nor any additional \'s help me out in this case.

Edit

If you are looking for using expressions (and a star) inside of a geom_label, text (annotate) or some other geometric that uses text from a data.frame (i.e., you assign the value within the aes-function), then this might help you.

If you want to use an expression (and a star) within an axis-label, title, or other text that is directly assigned outside of the aes-function (i.e., labs(x = "my expresion here")), then this question will help you out!

1 Answers
Related