5

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
L.D.
  • 51
  • 3

1 Answers1

4

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

Sathish
  • 12,453
  • 3
  • 41
  • 59