【问题标题】:Greek letters in ggplot annotateggplot 中的希腊字母注释
【发布时间】:2014-07-28 00:51:13
【问题描述】:

我想在 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 但做不到。我尝试了以下代码,但没有任何反应:

temp <- list(bquote(theta == .(xIntercept)))
temp <- bquote(theta == .(xIntercept))
temp <- expression(theta, "=", xIntercept)
temp <- c(expression(theta), paste0("=", xIntercept))

【问题讨论】:

    标签: r ggplot2


    【解决方案1】:

    您的链接指出在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)
    

    【讨论】:

    • temp &lt;- paste("theta == ", xIntercept) 将保留等号。
    • 效果很好。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-17
    • 1970-01-01
    • 1970-01-01
    • 2021-10-31
    • 1970-01-01
    • 2021-07-16
    相关资源
    最近更新 更多