Search code examples
rggplot2unicodesubscript

Subscripts not showing up in my secondary axis in ggplot2


Exactly as the title shows. Trying to use unicode (since brackets are not registering and just showing up as brackets) to create a subscript 2. The mu works fine. The subscripts 2 shows up as an unrecognized character box. Here is the code and an image of what I am talking about. I am open to anything!

enter image description here

scale_y_continuous(expand = c(0, 0), breaks = c(0,4,8,12,16,20), 
      limits = c(0,20), sec.axis=sec_axis(~.*50, 
      breaks = c(100,200,300,400,500,600,700,800,900,1000), 
      name = "Hydrogen Sulfide Concentration (\U00B5M H\U2082S)"))

Solution

  • You can use expression and paste:

    name = expression(paste("Hydrogen Sulfide Concentration (", mu, "M H" ["2"], "S)"))