Search code examples
rplotmath

In R, how to control spacing within mathematical annotations in plots


I'm trying to insert mathematical expressions into the titles of plots. I need to control the spacing within the mathematical expressions. For example, I'd like to show the expression "64/8 / 8" except with division signs instead of slashes. I need narrow spacing around the first division sign and broad spacing around the second. How can I do this?

Reproducible code:

# just produces uniform spacing:
plot( runif(10), runif(10) )
title( expression( 64 %/% 8 %/% 8 ) )

# returns an error
plot( runif(10), runif(10) )
title( expression( 64 %/% 8 ~ " " ~ %/% ~ " " 8 ) )

Solution

  • I second @MrFlick's comment above, but here is one way using phantom:

    title(expression(paste(64 %/% 8, phantom(0) %/% phantom(0), 8)))