Add a footnote citation outside of plot area in R?

后端 未结 3 1888
终归单人心
终归单人心 2021-01-30 17:10

I\'d like to add a footnote citation to my 3-panel facet grid plot produced in R. It\'s a footnote to credit the data source. I\'d ideally like to have it below and external t

相关标签:
3条回答
  • 2021-01-30 17:47

    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))
    
    0 讨论(0)
  • 2021-01-30 17:50

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

    0 讨论(0)
  • 2021-01-30 17:58
    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.

    0 讨论(0)
提交回复
热议问题