4

I need to find a way to place text 1 inch below the plot. I need that text to be 1 inch below the plot even if I change the margins of the plot or use different data. I’ve been calling grid text with tinkered x and y values, but I want something that will adapt to the dimension of the ggplot. Another approach is to use grobs (see related post) but that would require setting Y positions based on the data.

Here is the basic code:

library(ggplot2)
test= data.frame(
x = c(1:10 ),
y = c(1:10)
)

qplot(x=x, y=y, data=test)+  
opts(plot.margin = unit(c(1,3,8,1), "lines")) +  
geom_line()

enter image description here

Thanks you.

Community
  • 1
  • 1
Max C
  • 2,573
  • 4
  • 23
  • 28

1 Answers1

7

If you know how many lines you've added to the bottom margin (in this case 8) then I think you can do this with only some unit math:

grid.text("Here",y = unit(8,"lines") - unit(1,"inches"))
joran
  • 169,992
  • 32
  • 429
  • 468