ggplot2 facet贴标机双下标

时间:2016-02-03 18:35:47

标签: r ggplot2 facet facet-wrap

我用双下标绘制变量,我希望能够让下标在facet strip文本中保持一致。每个标签应显示类似$ \ 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)

enter image description here

1 个答案:

答案 0 :(得分: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

enter image description here