Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ggplot2 footnote

Tags:

r

pdf

ggplot2

What is the best way to add a footnote to the bottom of a plot created with ggplot2? I've tried using a combination of the logic noted here as well as the ggplot2 annotate function.

p + annotate("text",label="Footnote",
  x=unit(1,"npc") - unit(2, "mm"),y=unit(2, "mm"),
  just=c("right", "bottom"),gp=gpar(cex= 0.7, col=grey(.5)))

but I am getting the error

Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) : cannot coerce class c("unit.arithmetic", "unit") into a data.frame

like image 704
user338714 Avatar asked Jun 14 '10 17:06

user338714


2 Answers

labs(caption = "my caption") adds a footnote:

ggplot(mtcars, aes(mpg, wt, colour = cyl)) + 
  geom_point() + 
  labs(caption = "(Pauloo, et al. 2017)")

enter image description here

like image 195
Rich Pauloo Avatar answered Sep 25 '22 19:09

Rich Pauloo


I would use something like that:

pdf("filename.pdf", width=10, height=6) # open an appropriate graphics device
print(p)
makeFootnote() # from webpage above (uses grid.text; ggplot2 is based on grid)
dev.off()
like image 25
rcs Avatar answered Sep 24 '22 19:09

rcs