2

How can I insert a log symbol, in a ggplot text?

These were my tries:

myLabel = c("log_a b","log{a}")

ggplot(
    data=data.frame(x=0,y=0)
  ) + geom_point(
    aes(x=x,y=y)
  ) + annotate(
    'text', 
    x = 0, y = 0, 
    parse = TRUE,size=10,
    label = myLabel[2])  # here

Note: The above was taken from this post

Gilgamesh
  • 589
  • 1
  • 6
  • 20

1 Answers1

3

Do you mean something like this?

ggplot(data.frame(x = seq(1:10), y = seq(1:10), label = "log[10]"), aes(x, y, label = label)) +
    geom_text(parse = T) +
    annotate("text", x = 1, y = 5, label = "2^log[2]", parse = T)

enter image description here

See this link for a list of mathematical expressions in plotmath.

Maurits Evers
  • 49,617
  • 4
  • 47
  • 68