0

I am working on a plot in which I have scaled the horizontal axis by a factor of ten thousand. I've been trying to include that in my axis label, but have consistently failed. However, what I've found is that this works:

g <- g + xlab(expression(paste("Word Count ", (x %.% 10^4))))

but this does not:

g <- g + xlab(expression(paste("Word Count ", (%.% 10^4))))

The latter throws the error "Unexpected special in...".

Were I to be writing the label I wanted in LaTeX, it would be: $\text{Word Count } \left( \cdot 10^4 \right)$.

How do I get the axis label I'm after without the extra character?

Karl Wolfschtagg
  • 425
  • 2
  • 10
  • 1
    Your expressions must always be valid R syntax. Try `xlab(expression("Word Count " %.% 10^4))`. There's no need for `paste()`. Or if you really need the parenthesis around the dot, you cay use `xlab(expression("Word Count " ~ (phantom() %.% 10^4)))`. See the `?plotmath` help page for more info. – MrFlick Jan 06 '22 at 19:04

1 Answers1

0

For whatever reason, expression needs something on the left-hand side. However, that something can be NULL, so this works:

g <- g + xlab(expression(paste("Word Count ", (NULL %.% 10^4))))
Karl Wolfschtagg
  • 425
  • 2
  • 10