Adding expression to ggplot axis label seems to require an extra character?

1.1k views Asked by At

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?

1

There are 1 answers

0
Karl Wolfschtagg On BEST ANSWER

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))))