gpt4 book ai didi

r - ggplot 中的希腊字母注释

转载 作者:行者123 更新时间:2023-12-02 03:09:16 26 4
gpt4 key购买 nike

我想将希腊字母添加到 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))

最佳答案

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

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

有效并给出希腊西塔符号。编辑:但是 = 符号也被解析,所以 MrFlick注意到你应该去

temp <- paste("theta == ", xIntercept)

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com