【问题标题】:ggplot2 facet labeller double subscriptggplot2 facet labeller 双下标
【发布时间】:2016-05-13 02:50:16
【问题描述】:

我正在绘制带有双下标的变量,并且我希望能够防止下标在构面条文本中混合在一起。每个标签应该显示类似 $\beta_{1, 12}$ 而不是 $\beta_112$。修复以下 MWE 应该足够了。

d = data.frame(
  x = rnorm(6),
  y = rnorm(6), 
  z = rep(paste0("beta[", 1:3, "][", 12, "]"), each = 2))
library(ggplot2)
pl = ggplot(d) + 
  geom_point(aes(x, y)) + 
  facet_wrap(~z, labeller = label_parsed)

【问题讨论】:

  • 那么B122中的1和12之间应该插入逗号吧?我认为这就是你想要的,但你没有提到逗号。​​
  • 逗号可以使用,但任何其他既明显又美观的分隔符也可以。
  • 看起来不是最好的,也没有更改分隔符的选项,但确实完成了目标更改 zz = rep(paste0("beta[list(", 1:3, ",", 12, ")]"), each = 2)) 并继续原样。

标签: r ggplot2 facet facet-wrap


【解决方案1】:

这个怎么样?

library(ggplot2)

d = data.frame(
  x = rnorm(6),
  y = rnorm(6), 
  z = rep(paste0("beta[", 1:3, "~~", 12, "]"), each = 2))
pl = ggplot(d) + 
  geom_point(aes(x, y)) + 
  facet_wrap(~z, labeller = label_parsed)
pl

【讨论】:

  • 看起来不错。我更喜欢第 6 行中的“~”而不是“~~”,但这只是我的意见。您从哪里得知波浪号的用法?
  • 谢谢。浏览此内容以查找更多此类内容:stat.ethz.ch/R-manual/R-devel/library/grDevices/html/…
  • 所以 facet "labeller" 遵守 plotmath 规则。感谢您的帮助。
  • 是的,如果您查看label_parsed 的代码(只需从控制台输入不带括号的名称),您可以看到它是如何使用parse 构建的。
猜你喜欢
  • 1970-01-01
  • 2014-03-19
  • 2015-08-24
  • 1970-01-01
  • 2021-12-23
  • 2019-04-12
  • 1970-01-01
  • 2022-09-23
  • 1970-01-01
相关资源
最近更新 更多