如何在传说和情节区外注释ggplot2 qplot? (类似于mtext()) [英] How to annotate ggplot2 qplot outside of legend and plotarea? (similar to mtext())
本文介绍了如何在传说和情节区外注释ggplot2 qplot? (类似于mtext())的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用文件名注释我的图。使用 plot()
我使用了 mtext
:
<$ p $ ($ 10)
mtext(File xy-12-34-56.csv,4)
我如何使用ggplot2和qplot或ggplot来做到这一点?它不应该与传说相冲突。
我找到了命令 annotate
和 grid
,但我无法获得类似于<$ c的注释
作为解决方法,我可以尝试水印,但也许你对我有好的提示。
亲切的问候,乔纳斯
解决方案
更新 b $ b
看起来现在我们应该使用以下的结果:
library(ggplot2)
文库(网格)
库(gridExtra)
p <-qplot(data = mtcars,wt,mpg)
grid.arrange(p,right = textGrob(File xy-12-
$ / code>
回答
试试这个:
library(gridExtra )
p <-qplot(data = mtcars,wt,mpg)
print(arrangeGrob(p,legend = textGrob(File xy-12-34-56.csv,rot = -90, vjust = 1)))
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
解决方案
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)))
这篇关于如何在传说和情节区外注释ggplot2 qplot? (类似于mtext())的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文