title: How to position geom_text to the top of the image?
body: <p>I have a R script that I fail to figure out how to position the linear model text to the top of the plot.</p>
  
  <p><a href="https://i.stack.imgur.com/IywsD.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IywsD.jpg" alt="enter image description here"></a></p>
  
  <p>Obviously, the equation has been truncated at the left of the picture. How to position it to the centre and top of the screen?</p>
  
  <pre><code>library('ggplot2')
  
  # Convert a linear model to string
  lm_eqn &lt;- function(d)
  {
      m &lt;- lm(y ~ x, d);
      eq &lt;- substitute(italic(y) == a + b * italic(x)*","~~italic(r)^2~"="~r2, 
                       list(a  = format(coef(m)[1], digits = 2), 
                            b  = format(coef(m)[2], digits = 2), 
                            r2 = format(summary(m)$r.squared, digits = 3)))
      as.character(as.expression(eq));
  }
  
  x &lt;- c(1.000000, 1.000000, 512.000000, 0.007812, 0.500000, 128.000000, 0.031250, 8.000000, 1.000000, 0.125000, 1.000000, 0.001953, 1.000000, 512.000000, 1.000000, 1.000000, 1.000000, 0.031250, 8.000000, 1.000000, 1.000000, 1.000000, 2.000000, 0.007812, 32.000000, 1.000000, 128.000000, 2.000000, 0.500000, 2.000000)
  y &lt;- c(1.113178, 0.031777, 0.906857, 0.013068, 27.345812, 1.284633, 12.339972, 15.743898, 0.047385, 21.390038, 5.088041, 0.323969, 14.430306, 1.236607, 46.641335, 2305.140560, 0.243231, 4.332996, 14.797866, 0.247129, 3.616768, 1.527917, 53.360089, 0.269371, 9.797017, 3.893512, 0.388018, 38.573338, 9.828420, 0.238145)
  
  # Names of the sequin for each data-point
  ids &lt;- c('GC_24_2','M11_G','M9_G','MG_22','MG_23','MG_24','MG_28','MG_3','MG_30','MG_32','MG_33','MG_34','MG_36','MG_37','MG_44','MG_46','MG_47','MG_50','MG_52','MG_53','MG_55','MG_57','MG_6','MG_60','MG_61','MG_62','MG_63','MG_68','MG_71','MG_8')
  
  lx &lt;- log2(x)
  ly &lt;- log2(y)
  d  &lt;- data.frame(x=lx, y=ly, ids=ids)
  
  p &lt;- ggplot(data = d, aes(x = x, y = y))
  p &lt;- p + xlab('Expected log2 fold change of mixture A and B')
  p &lt;- p + ylab('Measured log2 fold change of mixture A and B')
  p &lt;- p + geom_point()
  p &lt;- p + xlim(min(lx)-1, max(lx)+1)
  p &lt;- p + ylim(min(ly)-2, max(ly)+2)
  p &lt;- p + ggtitle("Plant growth with\ndifferent treatments")
  p &lt;- p + geom_smooth(method = "lm", formula = y ~ x)
  p &lt;- p + geom_text(x = min(d$x), y = max(d$y), label = lm_eqn(d), parse = TRUE)
  print(p)
  </code></pre>