【问题标题】:How can I strip a leading zero from an expression rendered by plotmath?如何从 plotmath 呈现的表达式中去除前导零?
【发布时间】:2021-07-25 22:00:29
【问题描述】:

由于期刊的要求,我需要将 p 值格式化为大写、斜体 P 以及不带前导零的值本身,例如 P = .01。我想在我的图中包含一些 p 值标签。

我的麻烦是我需要使用plotmath expressions 来呈现斜体P(据我所知),但plotmath 总是以前导零呈现值,即使我输入一个没有它的字符串。举个例子

ggplot2::ggplot(data.frame(x = 1, y = 1)) +
  ggplot2::geom_text(x = 1, y = 1, label = "italic(P) == .01", parse = TRUE)

由reprex package (v1.0.0) 于 2021 年 5 月 3 日创建

有人知道这个问题的解决方案吗?我想要么用plotmath 删除前导零,要么在不带plotmath 的情况下将P 斜体化。

【问题讨论】:

    标签: r plotmath


    【解决方案1】:

    一种方法是将数字用作字符串。

    ggplot2::ggplot(data.frame(x = 1, y = 1)) +
      ggplot2::geom_text(x = 1, y = 1, label = "italic(P) == '.01'", parse = TRUE)
    

    【讨论】:

    • 太棒了!非常感谢=]
    猜你喜欢
    • 1970-01-01
    • 2013-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-27
    相关资源
    最近更新 更多