Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ggplot strip文本中的希腊字母_R_Ggplot2 - Fatal编程技术网

ggplot strip文本中的希腊字母

ggplot strip文本中的希腊字母,r,ggplot2,R,Ggplot2,我试图覆盖一些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))

我试图覆盖一些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()
我推测我应该向
facet\u grid
添加一个labeller参数来覆盖文本。我认为这应该抛出一个表达式来处理希腊字符,但我的代码只是在打印图形时抛出一个错误

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'
lbl试试这个:

p + facet_grid(fy ~ fx, labeller = label_parsed)

在此处发布此内容,因为它是相关的:

如果希望变量本身的名称以及变量的级别/值作为表达式进行计算(即,将其呈现为latex),请尝试以下操作:

label_parseall <- function(variable, value) {
    plyr::llply(value, function(x) parse(text = paste(variable, 
        x, sep = "==")))
}

label\u parseall我看到这个答案是有效的,但我不知道怎么做。解析的标签从哪里来?我在在线ggplot文档中找不到它。它在包文档()中有简要提及;我同意可以有更好的文档记录——我只知道b/c我看到哈德利在某个时候提到过。谢谢——我现在看到了。这是一个可能非常有用的命令。
label_parseall <- function(variable, value) {
    plyr::llply(value, function(x) parse(text = paste(variable, 
        x, sep = "==")))
}
data <- data.frame(x = runif(10), y = runif(10), 
    gamma = sample(c("gamma[0]", "gamma[1]"), 10, rep = T))
ggplot(data, aes(x, y)) + geom_point() + facet_grid(~gamma, 
    labeller = label_parselabel)