如何在ggplot2中的geom_text()标签中添加希腊字母

5
我尝试用希腊字母kappa来标记geom_tile中的tiles,如下所示:

kappa = value

我尝试使用expression()和bquote(),但无法找到使其正常工作的方法。
df = data.frame(x = letters[1:10],y = letters[11:20], value = 1:10)

p = ggplot(df, aes(x = x, y = y)) +
  geom_tile()+geom_text(aes(label= paste("k = ",value,"")), color = "white")

p

[![enter image description here][1]][1]


  [1]: https://istack.dev59.com/5bDLv.webp

你可以尝试使用Unicode转义paste("\u03f0 =", value) - Allan Cameron
非常感谢!Kappa的代码是u03ba,但它运行得非常好! - L.D.
1个回答

4

使用parse = TRUE

通过查看?plotmath了解绘图中使用的数学表达式。

ggplot(df, aes(x = x, y = y)) +
  geom_tile() +
  geom_text(mapping = aes(label = paste('kappa', "==", value)), parse = TRUE, color = "white")

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接