I want to position a plotmath symbol (x bar) in a plot using ggplot2. Somehow the way I do it alters the legend. The letter "a" suddenly appears. Where do I go wrong here?
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)
This will fix the problem:
ggplot(d, aes(x, y, group = g)) +
geom_point(aes(colour = g)) +
geom_text(x = 0, y = 0, label = "bar(x)", parse=T)
Only add colour the points.
Or, if you want to annotate the plot, annotations will not be placed in the legend so
ggplot(d, aes(x, y, group = g,colour = g)) +
geom_point() +
annotate('text',x = 0, y = 0, label = "bar(x)", parse=T)
would work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With