How to place text exactly 1 inch below a plot generated by ggplot2?

ggplot2, r

Solution

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"))

Problem

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() ``` Thanks you.

Original source

Related problems