Add a footnote citation outside of plot area in R?

人走茶凉 提交于 2019-12-02 16:17:13
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)

Edit: note that this solution is somewhat complementary to the recent caption argument added to ggplot2, since the textGrob can here be aligned with respect to the whole figure, not just the plot panel.

ggplot2 now has this ability natively with no need for additional packages. ... + labs(caption = "footnote", ...)

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

Adding to the answer of Brandon Bertelsen: if you want to have the caption in the left corner, add

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