我想在ggplot中的文本中添加希腊字母。这是我想做的:

library(ggplot2)
df <- data.frame(x =  rnorm(10), y = rnorm(10))
xIntercept <- mean(df$x)
yIntercept <- mean(df$y)
temp <- paste("theta = ", xIntercept) # This Works
ggplot(df, aes(x = x, y = y)) + geom_point() +
  annotate("text", x = xIntercept, y = yIntercept, label = temp, color = "blue")

我想使用希腊字母theta代替“theta”。我尝试了这个link,但无法做到。我尝试了以下代码,但没有任何 react :
temp <- list(bquote(theta == .(xIntercept)))
temp <- bquote(theta == .(xIntercept))
temp <- expression(theta, "=", xIntercept)
temp <- c(expression(theta), paste0("=", xIntercept))

最佳答案

您的链接指出,在annotate中,您应该使用parse = TRUE。所以

ggplot(df, aes(x = x, y = y)) + geom_point() +
  annotate("text", x = xIntercept, y = yIntercept, label = temp, color = "blue", parse = TRUE)

的作品,并给出一个希腊的theta符号。
编辑:但是=符号也被解析,因此MrFlick指出您应该
temp <- paste("theta == ", xIntercept)

关于r - ggplot中的希腊字母注释,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24987158/

10-12 19:34