在R中绘图区域外添加脚注引用?
我想在我用R生成的3面板镶嵌面网格图中添加一个脚注引用。这是一个脚注,用于证明数据源。理想情况下,我希望它位于所有三个轴的下方和外部,最好位于左下角 我正在使用在R中绘图区域外添加脚注引用?,r,ggplot2,annotations,r-grid,R,Ggplot2,Annotations,R Grid,我想在我用R生成的3面板镶嵌面网格图中添加一个脚注引用。这是一个脚注,用于证明数据源。理想情况下,我希望它位于所有三个轴的下方和外部,最好位于左下角 我正在使用ggplot2和ggsave()。这意味着我不能使用基于grid.text()的解决方案,因为这只会绘制x11()窗口,并且不能添加到ggplot对象 而是使用png()…代码。。。dev.off()似乎不是一个选项,因为我需要ggsave的大小调整参数,并发现此命令可以生成更好、更清晰的打印(打印速度也更快,因为我没有打印到屏幕上) 这
ggplot2
和ggsave()
。这意味着我不能使用基于grid.text()
的解决方案,因为这只会绘制x11()
窗口,并且不能添加到ggplot对象
而是使用png()…代码。。。dev.off()
似乎不是一个选项,因为我需要ggsave
的大小调整参数,并发现此命令可以生成更好、更清晰的打印(打印速度也更快,因为我没有打印到屏幕上)
这是我的基本代码:
p1 <- ggplot(data, aes(date, value))
facet_grid(variable ~ .) + geom_point(aes(y =value), size=1) +
theme_bw() +
opts(title=mytitle)
print(p1)
ggsave("FILE.png",width=mywidth, height=myheight, p1, dpi=90)
p1库(gridExtra)
图书馆(网格)
图书馆(GG2)
gggplot2现在本机具有此功能,无需额外的软件包<代码>…+实验室(caption=“footnote”,…)
在布兰登·贝尔特森的回答中添加:如果您想在左角添加标题,请添加
theme(plot.caption = element_text(hjust = 0))
这种方法似乎不适用于gridExtra_0.8.1和ggplot2_0.9.3.1,在开关中出现错误消息error(ct,ggplot=ggplotGrob(grobs[[ii.表]])、网格=latticeGrob(grobs[[ii.表]]),:EXPR必须是长度为1的向量
,这就是为什么您应该将gridExtra更新为当前版本这似乎与gridExtra的2.0.0版本不同–不再支持sub=
参数,并且arrangeGrob()
返回一个TableGrob而不是ggplot继承的对象。@Tom ggplot2的开发版本现在允许ggsave
从arrangeGrob()
保存对象。请参阅。鉴于程序包作者(此答案的同一作者)重新写入gridExtra,提供的解决方案在最新的gridExtra软件包中不再可行。您可以执行以下操作:grid.arrange(g,ncol=1,bottom=“footnote”)+ggthemes::theme\u economist
p1 <- ggplot(data, aes(date, value))
facet_grid(variable ~ .) + geom_point(aes(y =value), size=1) +
theme_bw() +
opts(title=mytitle) +
annotate("text", label = "Footnote", x = 0, y = 10, size = 5, colour = "black") +
print(p1)
ggsave("FILE.png",width=mywidth, height=myheight, p1, dpi=90)
library(gridExtra)
library(grid)
library(ggplot2)
g <- grid.arrange(qplot(1:10, 1:10, colour=1:10) + labs(caption="ggplot2 caption"),
bottom = textGrob("grid caption", x = 1,
hjust = 1, gp = gpar(fontface = 3L, fontsize = 9)))
ggsave("plot.pdf", g)
library(ggplot2)
ggplot(diamonds, aes(carat, price, color = clarity)) +
geom_point() +
labs(title = "Diamonds are forever...",
subtitle = "Carat weight by Price",
caption = "H. Wickham. ggplot2: Elegant Graphics for Data Analysis Springer-Verlag New York, 2009.")
theme(plot.caption = element_text(hjust = 0))