I would like to add a link to a footnote to my 3-panel bar graph created in R. This is a footnote for lending to a data source. Ideally, I would like to have it lower and external in relation to all three axes - preferably in the lower left corner.
I am using ggplot2 as well as ggsave() . This means that I cannot use grid.text() based grid.text() because it only draws the x11() window and cannot be added to the ggplot object.
Using instead of png() ...code... dev.off() not an option because I need ggsave resizing ggsave and this command produces better and sharper prints (this is also much faster because I don't print on the screen).
Here is my base code:
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)
I tried:
p1 <- ggplot(data, aes(date, value)) facet_grid(variable ~ .) + geom_point(aes(y =value), size=1) + theme_bw() + opts(title=mytitle) print(p1) grid.text(unit(0.1,"npc"),0.025,label = "Data courtesy of Me") grid.gedit("GRID.text", gp=gpar(fontsize=7)) ggsave("FILE.png",width=mywidth, height=myheight, p1, dpi=90)
This correctly places the footnote in the lower left corner on the x11 () screen, external to the graphs, but unfortunately, since it does not apply to the p1 object, it is not saved by the ggsave command.
I also tried:
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)
This prints successfully with ggsave, however it has the following problems:
- Repeated 3 times in each of the three faces, and not 1 time.
- It is contained within the plots, and not external to them.
- The text is difficult to place --- it seems plot units are used (my x axis is the date, so 0 puts it in 1970).
- The text size does not change, despite my size setting.
A few related links when I learned this ...
ggplot2 footnote
(does not work with ggsave)
How to tag barplot in ggplot with shortcuts in another test result?
(located inside the chart, not external / below the chart)
Various fonts and font sizes in text entries in ggplot2
(does not work with ggsave)
problem saving pdf file to r using ggplot2