我正在尝试覆盖某些 ggplot 条带中的文本以包含希腊字符。这是一些示例数据,以及该图的基础。
dfr <- data.frame(
x = rep(1:10, times = 6),
y = runif(60),
fx = rep(c("foo", "bar"), each = 30),
fy = rep(c("alpha", "beta", "gamma"), each = 10, times = 2)
)
p <- ggplot(dfr, aes(x, y)) + geom_point()
我第一次尝试的情节标签中没有希腊语。
p + facet_grid(fy ~ fx)
我认为我应该添加一个 labeller 参数facet_grid
来覆盖文本。我认为这应该吐出一个表达式来处理希腊字符,但我的代码只是在打印图形时抛出一个错误。
lbl <- function(variable, value)
{
if(variable == "fy") parse(text=as.character(value)) else value
}
p + facet_grid(fy ~ fx, labeller = lbl)
Error in aperm(X, c(s.call, s.ans)) :
unimplemented type 'expression' in 'aperm'
我应该如何创建条形标签?