在ggplot2中使用plotmath符号geom_text - 图例被改变了 - 为什么?

Mar*_*ann 2 r ggplot2

我想使用ggplot2在plot中定位plotmath符号(x bar).不知怎的,我这样做会改变传说.字母"a"突然出现.我在哪里出错?

d <- data.frame(x=rnorm(10), y=rnorm(10), g=rep(c("m", "w"), 5))
ggplot(d, aes(x, y, group=g, color=g)) + geom_point() +
    geom_text(x=0, y=0, label="bar(x)", parse=T)
Run Code Online (Sandbox Code Playgroud)

mne*_*nel 7

这将解决问题:

ggplot(d, aes(x, y, group = g)) +   
  geom_point(aes(colour = g)) + 
  geom_text(x = 0, y = 0, label = "bar(x)", parse=T)
Run Code Online (Sandbox Code Playgroud)

只添加颜色点.

或者,如果要注释绘图,则注释不会放在图例中

ggplot(d, aes(x, y, group = g,colour = g)) +   
  geom_point() + 
  annotate('text',x = 0, y = 0, label = "bar(x)", parse=T)
Run Code Online (Sandbox Code Playgroud)

会工作.