Search code examples
rggplot2expressionplotmath

Axis title containing texts with exponents


I'm using ggplot2 to plot a chart. I want to add an exponent to a text within the Y-axis title, so it would look like this:

Energy (kcal ∙ mol-1)

I usually write the axis title text inside labs () and its aesthetic inside theme (axis.title.y = element_text ()). I've seen this answer, but I couldn't understand any of it...


Solution

  • Probably a duplicate question. Check this question for detailed answers.

    You can build an expression

    ggplot() + geom_point(aes(x=1, y=1)) + 
      labs(y=expression('Energy (kcal '~mol^-1*')'))
    

    plot