Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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
like image 348
L.D. Avatar asked Apr 02 '20 21:04

L.D.


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

like image 101
Sathish Avatar answered Sep 30 '22 21:09

Sathish