title: Plot a GLM, R squared and p-value in R base plot
body: <p>I have data on the monthly number of people varying with a variable (a count) over a period of 30 years, 1987-2018. I have divided this period in three shorter periods to check whether the correlation is approximately the same then and now, fitting a model with the var as a response, the number of people and periods as predictors, and a Poisson distribution for the response.</p>
  <p>I have made this script in ggplot, but want to make it work in the basic R plot mode. I also want the equation, R squared and the p-value in each of the three plots. This script works in ggplot:</p>
  <pre><code>library(ggplot2)
  p &lt;- ggplot(df, aes(people,var)) + geom_point()
  p + facet_grid(rows=vars(period))
  p + facet_grid(rows=vars(period)) + 
     stat_smooth(method=&quot;glm&quot;, method.args = list(family = &quot;poisson&quot;))
  summary(glm(var~people+period, family=poisson, data=df))
  </code></pre>
  <p>And it makes this plot:
  <a href="https://i.stack.imgur.com/JUZor.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JUZor.png" alt="enter image description here" /></a></p>
  <p>Here's the data:</p>
  <pre><code>&gt; dput(df)
  structure(list(period = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
  1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 
  3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), month = c(&quot;JAN&quot;, 
  &quot;FEB&quot;, &quot;MAR&quot;, &quot;APR&quot;, &quot;MAY&quot;, &quot;JUN&quot;, &quot;JUL&quot;, &quot;AUG&quot;, &quot;SEP&quot;, &quot;OCT&quot;, 
  &quot;NOV&quot;, &quot;DEC&quot;, &quot;JAN&quot;, &quot;FEB&quot;, &quot;MAR&quot;, &quot;APR&quot;, &quot;MAY&quot;, &quot;JUN&quot;, &quot;JUL&quot;, 
  &quot;AUG&quot;, &quot;SEP&quot;, &quot;OCT&quot;, &quot;NOV&quot;, &quot;DEC&quot;, &quot;JAN&quot;, &quot;FEB&quot;, &quot;MAR&quot;, &quot;APR&quot;, 
  &quot;MAY&quot;, &quot;JUN&quot;, &quot;JUL&quot;, &quot;AUG&quot;, &quot;SEP&quot;, &quot;OCT&quot;, &quot;NOV&quot;, &quot;DEC&quot;), people = c(4068L, 
  7251L, 14384L, 20513L, 18748L, 17760L, 23433L, 22878L, 12815L, 
  8101L, 7477L, 5018L, 5063L, 11103L, 20946L, 32192L, 22665L, 29605L, 
  37590L, 36692L, 16474L, 8989L, 5729L, 3909L, 8391L, 18638L, 31223L, 
  40583L, 26889L, 40074L, 53218L, 52087L, 23873L, 13694L, 9354L, 
  9822L), var = c(2L, 1L, 3L, 5L, 3L, 0L, 4L, 5L, 1L, 1L, 0L, 1L, 
  0L, 2L, 1L, 1L, 4L, 1L, 3L, 4L, 0L, 0L, 0L, 1L, 0L, 0L, 2L, 6L, 
  1L, 2L, 2L, 3L, 1L, 0L, 0L, 0L)), class = &quot;data.frame&quot;, row.names = c(NA, 
  -36L))
  </code></pre>