簡體   English   中英

ggplot中的希臘字母注釋

[英]Greek letters in ggplot annotate

我想在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”。 我嘗試了此鏈接,但無法做到。 我嘗試了以下代碼,但沒有任何反應:

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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM