简体   繁体   English

ggplot中的希腊字母注释

[英]Greek letters in ggplot annotate

I want to add greek letters into text in ggplot. 我想在ggplot中的文本中添加希腊字母。 Here is what I want to do: 这是我想做的:

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")

Instead of "theta", I want to use Greek letter theta. 我想使用希腊字母theta代替“ theta”。 I tried this link but cannot do it. 我尝试了此链接,但无法做到。 I tried following codes but nothing happened: 我尝试了以下代码,但没有任何反应:

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

Your link states that in annotate you should use parse = TRUE . 您的链接指出,在annotate应使用parse = TRUE So 所以

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

works and gives a greek theta symbol. 的作品,并给出一个希腊的theta符号。 EDIT: However the = sign is parsed too, so as MrFlick noted you should go for 编辑:但是=符号也被解析,因此MrFlick指出您应该

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM