我想使用ggplot2在绘图中放置绘图符号(x栏)。我以某种方式改变了传奇。字母“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)

最佳答案

这将解决问题:

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)

会工作。

关于r - 在ggplot2中使用plotmath符号geom_text-图例已更改-为什么?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11408031/

10-12 17:36
查看更多