How to add greek letters to a label in geom_text() label in ggplot2

Viewed 744

I am trying to label the tiles in geom_tile with the Greek symbol, kappa, as follows

kappa = value

I've tried using expression() and bquote() but cannot find a way to make it work

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://i.stack.imgur.com/5bDLv.png
1 Answers

use parse = TRUE

also learn more about mathematical expressions used in plot by following this: ?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

Related