当您想向您添加数学符号时,facet_wrap
您曾经能够使用grid
包(示例取自此处):
library(ggplot2); library(grid)
d <- ggplot(diamonds, aes(carat, price, fill = ..density..))
xlim(0, 2) + stat_binhex(na.rm = TRUE) + opts(aspect.ratio = 1)
d <- d + facet_wrap(~ color, ncol = 4)
grob <- ggplotGrob(d)
strip_elem <- grid.ls(getGrob(grob, "strip.text.x", grep=TRUE, global=TRUE))$name
grob <- editGrob(grob, strip_elem[1], label=expression(Y[1]))
grid.draw(grob)
这不再有效,因为它给出了这个错误:
> strip_elem <- grid.ls(getGrob(grob, "strip.text.x", grep=TRUE, global=TRUE))$name
Error in getGrob(grob, "strip.text.x", grep = TRUE, global = TRUE) :
It is only valid to get a child from a 'gTree'
> grob <- editGrob(grob, strip_elem[1], label=expression(Y[1]))
Error in editGrob(grob, strip_elem[1], label = expression(Y[1])) :
object 'strip_elem' not found
我们如何在 0.9.2 版本中添加数学符号?