title: Fit poisson distribution to data (histogram + line)
body: <p>I need to do exactly what @interstellar asked here <a href="https://stackoverflow.com/questions/38249508/fit-poisson-distribution-to-data">Fit poisson distribution to data</a> but within the R environment (not matlab).</p>
  
  <p>So, I created a barplot with my observed values and I just need to fit a poisson distribution on it.</p>
  
  <p>Here my data:</p>
  
  <pre><code>df = read.table(text = 'Var1 Freq     
      6    1
      7    2
      8    5
      9    7
     10    9
     11    6
     12    4
     13    3
     14    2
     15    1', header = TRUE)
  </code></pre>
  
  <p>the barplot created is the following:</p>
  
  <pre><code>t = barplot(df$Freq, ylim = c(0,10))
  axis(1, at=t, labels=df$Var1)
  </code></pre>
  
  <p>I am still new to R so how I could use the <code>fitdist</code> function or something else to create a line above my barplot?</p>
  
  <p>Any help would be really appreciated.</p>
  
  <p>UPDATE</p>
  
  <p>I have worked out something but I am not sure 100% if it is correct:</p>
  
  <pre><code>#create barplot
  t = barplot(df$Freq, ylim = c(0,10))
  axis(1, at=t, labels=df$Var1)
  
  #find lambda value from my data
  pois = fitdist(df$Freq, 'pois', method = 'mle')
  print(pois)
  
  #result
  Fitting of the distribution ' pois ' by maximum likelihood 
  Parameters:
         estimate Std. Error
  lambda        4  0.6324555
  
  #create 10 values from a real poisson distribution
  dist = dpois(1:10, lambda = 4)
  
  #multiply them by `sum(df$Freq)` in order to scale them to the barplot
  dist = dist * sum(df$Freq)
  
  #add the line plot to the original barplot
  lines(dist, lwd = 2)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/XaEJ9.png" rel="nofollow noreferrer">result</a></p>
  
  <p>However, the curve is not smooth..</p>