如何在图例和plotarea之外注释ggplot2 qplot? (类似于mtext())

时间:2023-02-09 21:39:08

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

我想用文件名注释我的情节。使用plot()我使用了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.

我怎么能用ggplot2和qplot或ggplot来做到这一点?它不应该与传说碰撞。我发现命令注释和网格,但我无法获得类似于mtext的注释。

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

作为一种解决方法,我可以尝试水印,但也许你对我有好的暗示。亲切的问候,乔纳斯

1 个解决方案

#1


13  

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

如何在图例和plotarea之外注释ggplot2 qplot? (类似于mtext())

#1


13  

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

如何在图例和plotarea之外注释ggplot2 qplot? (类似于mtext())