title: Trying to insert text box in ggplot. But the graph output is weird. Please find what i am doing wrong? How do i fix the code to show the text box?
body: <p>I am trying to insert a text box in my ggplot to show regression equation and p-value but it is giving me a weird output. The graph only shows on one side. please look at the image.</p>
  
  <p>I also tried to use:</p>
  
  <pre><code>scale_x_continuous(name = "Year", limits=c(1890, 2020)
  </code></pre>
  
  <p>but it does not work.</p>
  
  <p>I adopted the following code and added the text in "geom_label" instead of in the title. </p>
  
  <p><a href="https://sejohnston.com/2012/08/09/a-quick-and-easy-function-to-plot-lm-results-in-r/" rel="nofollow noreferrer">https://sejohnston.com/2012/08/09/a-quick-and-easy-function-to-plot-lm-results-in-r/</a></p>
  
  <p><strong>if anyone can find my error. i will be greatful.</strong></p>
  
  <p>Here is the function that I tried to use: </p>
  
  <pre><code>ggplotRegression3 &lt;- function (fit) {
    require(ggplot2)
  
    ggplot(fit$model, 
           aes_string(x = names(fit$model)[2], y = names(fit$model)[1])) + 
      geom_point() + 
      geom_line() + 
      geom_label(aes(3, 40, hjust = 1, 
                     "Adj R2 = ",
                     signif(summary(fit)$adj.r.squared, 3),"\n",
                     "Intercept =",signif(fit$coef[[1]],3 ),"\n",
                     " Slope =",signif(fit$coef[[2]], 3),"\n",
                     " P-value =",signif(summary(fit)$coef[2,4], 3))) +
      stat_smooth(method = "lm", col = "red") +
      labs(title = "Average annual") + 
      scale_x_continuous(name = "Year", limits=c(1890, 2020)) 
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/Kp4Jj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Kp4Jj.png" alt="enter image description here"></a></p>