【问题标题】:leading superscript in plotmath expression (w/ggplot2)plotmath 表达式中的前导上标(w/ggplot2)
【发布时间】:2013-08-09 07:33:18
【问题描述】:

我想使用plotmath 在ggplot2 图中创建一个包含前导上标的轴。在轴标签上创建上标效果很好,如下所示:

require(ggplot2)
ggplot(mtcars, aes(x=disp, y=mpg)) + 
  geom_point() +
  ylab(expression(x[y]))

但是,我希望我的轴标签为“y(上标)x”——逻辑上应该是^yx,但不会解析:

Error: unexpected '^' in: "  
geom_point() + 
ylab(expression(^"

有没有办法在语句的开头强制使用上标?

【问题讨论】:

    标签: r ggplot2 plotmath


    【解决方案1】:

    这个怎么样:

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

    我确信一定有办法制作“占位符”字符,但我不得不在 ?plotmath 中向下滚动一点才能找到它。

    【讨论】:

    • 可能也只是使用了一个空的双引号。 expression(""^y * x)
    猜你喜欢
    • 2021-07-25
    • 2016-06-23
    • 2019-05-04
    • 2020-03-23
    • 2018-08-06
    • 2015-12-16
    • 2016-12-02
    • 2016-01-13
    • 2018-05-24
    相关资源
    最近更新 更多