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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.