在plotmath表达式中引出上标(w / ggplot2) [英] leading superscript in plotmath expression (w/ggplot2)
问题描述
我希望使用 plotmath
在 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]))
$ $ $ $ $ $ $ geom_point()+
ylab b
$ b
然而,我想让我的轴标签读取y(上标)x - 从逻辑上讲,这将是 ^ yx
,但那不会解析:
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?
推荐答案
这个如何:
How about this:
ggplot(mtcars, aes(x=disp, y=mpg)) +
geom_point() +
ylab(expression(phantom(0)^y * x))
我确定必须有办法做一个占位符字符,但我必须向下滚动在?plotmath
找到它。
I was certain there must be a way to do a "placeholder" character, but I had to scroll down a bit in ?plotmath
to find it.
这篇关于在plotmath表达式中引出上标(w / ggplot2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!