leading superscript in plotmath expression (w/ggplot2)

那年仲夏 提交于 2019-12-23 09:09:30

问题


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?


回答1:


How about this:

ggplot(mtcars, aes(x=disp, y=mpg)) + 
  geom_point() +
  ylab(expression(phantom(0)^y * x))

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.



来源:https://stackoverflow.com/questions/18111606/leading-superscript-in-plotmath-expression-w-ggplot2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!