2

Assume we have this simple plot:

ggplot(data = msleep, aes(x = log(bodywt), y = sleep_total)) + 
    geom_point(aes(color = vore)) + 
    theme(legend.position="bottom")

enter image description here

Is it possible to add a text below the legend items? I know how to add a title (above) the legend. But lets say I want some other general information written below.

Would be very pleased to find a solution to that.

Thanks! Martin

Tyler Rinker
  • 108,132
  • 65
  • 322
  • 519
Martin Schmelzer
  • 23,283
  • 6
  • 73
  • 98
  • 1
    @hrbrmstr I think this is a duplicate but not of what you posted. It's related but that's about a table. I think this is the dupe: http://stackoverflow.com/a/10346760/1000343 – Tyler Rinker Nov 28 '14 at 01:42

1 Answers1

6

This is one possible approach:

library(gridExtra)
library(grid)

p <- ggplot(data = msleep, aes(x = log(bodywt), y = sleep_total)) + 
    geom_point(aes(color = vore)) + 
    theme(legend.position="bottom", plot.margin = unit(c(1,1,3,1),"lines")) + 
    annotation_custom(grob = textGrob("Extra text.  Read all about it"),  
        xmin = 2, xmax = 2, ymin = -4.5, ymax = -4.55)


gt <- ggplot_gtable(ggplot_build(p))
gt$layout$clip[gt$layout$name=="panel"] <- "off"
grid.draw(gt)

enter image description here

Tyler Rinker
  • 108,132
  • 65
  • 322
  • 519