Wednesday, 7 August 2013

leading superscript in plotmath expression (w/ggplot2)

leading superscript in plotmath expression (w/ggplot2)

I'd like to use plotmath to create an axis containing a leading
superscript in a ggplot2 plot. Creating superscripts on axis labels works
nicely, like so:
require(ggplot2)
ggplot(mtcars, aes(x=disp, y=mpg)) +
geom_point() +
ylab(expression(x[y]))

However, I'd like to have my axis label read "y(superscript)x" - logically
that would be ^yx, but that won't parse:
Error: unexpected '^' in: "
geom_point() +
ylab(expression(^"
Is there a way to force a superscript at the beginning of a statement?

No comments:

Post a Comment