How to annotate ggplot2 qplot outside of legend and plotarea? (similar to mtext())

半城伤御伤魂 提交于 2019-11-27 06:50:23

问题


I would like to annotate my plots with a filename. With plot() I used mtext:

plot(1:10)
mtext("File xy-12-34-56.csv", 4)

How can I do that with ggplot2 and qplot or ggplot? It should not collide with the legend. I found the commands annotate and grid, but I could not get an annotation similar to mtext with these.

As a workaround I could try watermarks, but perhaps you have a good hint for me. Kind regards, Jonas


回答1:


Update

Looks like to achieve the result now we should use the following:

library(ggplot2)
library(grid)
library(gridExtra)
p <- qplot(data = mtcars, wt, mpg)
grid.arrange(p, right = textGrob("File xy-12-34-56.csv", rot = -90, vjust = 1))

Old answer

Try this:

library(gridExtra)
p <- qplot(data = mtcars, wt, mpg)
print(arrangeGrob(p, legend = textGrob("File xy-12-34-56.csv", rot = -90, vjust = 1)))



来源:https://stackoverflow.com/questions/13009135/how-to-annotate-ggplot2-qplot-outside-of-legend-and-plotarea-similar-to-mtext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!