5

I want to add two captions for the footer. But it seems that ggplot will only take 1. Is there a workaround to add an annotation or geom_text to the bottom left and right hand corners.

library(ggplot2)
p <- ggplot(mtcars, aes(x=wt, y = mpg)) + 
   geom_point()

p + labs(caption = "left footer") +  theme(plot.caption=element_text(hjust=0))


p + labs(caption = "right footer") +  theme(plot.caption=element_text(hjust=1))

p + labs(caption = "right footer") +  theme(plot.caption=element_text(hjust=1)) + 
    labs(caption = "left footer") +  theme(plot.caption=element_text(hjust=0))
vinchinzu
  • 534
  • 1
  • 6
  • 14

1 Answers1

8

I'm very late to the party here but I also had the same issue.

A solution to your question would be to place both the captions at the same time and treat them as vectors:

p + labs(caption = c("right footer", "left footer")) + 
theme(plot.caption = element_text(hjust=c(1, 0)))
James Allison
  • 81
  • 2
  • 3
  • Great solution, should be the accepted answer. Also works for multiple captions (>2). +1 – Mr.Rlover Feb 03 '21 at 14:49
  • It raises a warning message: `Vectorized input to element_text() is not officially supported.` – ah bon Jan 06 '22 at 05:31
  • I was looking for a solution for multiple captions. I did get the same warning, but it still gave me the desired effect. This answer works. – EastBeast Mar 25 '22 at 20:59