I want to add greek letters into text in 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. 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))
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…