Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
420 views
in Technique[技术] by (71.8m points)

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)))

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...