Search code examples
rplotmath

How to STOP superscripting in an R plot axis label when using grid


I have used 'grid' to put together some plots I made in ggplot, and then I used 'grid.text' to give these plots the same y-axis label. I eventually figured out how to get a superscript in there for -2, but I do not want the parenthesis following the two to be superscripted. This is the best line I've got so far, but it seems like no matter what I do, everything after that "^" is raised up.

grid.text((expression(paste("Biomass (g m"^"-2*)"))), rot = 90, vjust = -20.4)

Similar posts have been helpful so far, but I'm thinking that 'grid.text' just doesn't work the same as everything else I have read about.

Here is what the figure looks like:


Solution

  • The paste (and quotes) can be dropped. In this case they are not needed (and in many cases they are just getting in the way of economical expression). One advantage of using "(" in the native plotmath form is that the size is larger probably to accommodate possibility of exponents and subscripts.

    expression( Biomass~(g%.%m^-2) )
    

    I put in more mathematical cdot but you could revert back to a space btwn the g and m with;

    expression( Biomass~(g~m^-2) )
    

    To see the subtle difference in size of "(" and ")" you can try these two versions:

    grid.text(expression( Biomass~(g%.%m[3]^-2) ), rot = 90, vjust = -20.4)
    grid.text(expression( "Biomass~(g"%.%m[3]^-2*")" ), rot = 90, vjust = -20.4)
    

    The plotmath version is larger than the character version.