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

时间:2012-07-10 06:49:11

标签: 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)

1 个答案:

答案 0 :(得分:7)

这将解决问题:

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

只为点添加颜色。

或者,如果您想要注释图表,注释将不会放在图例中

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

会起作用。

相关问题