0

I am interested in comparison of visualization of dataset: histogram and density. I used dataset below for example only, however the idea is the same and it is for Poisson distribution: Could anyone help me to plot display this with ggplot2?

example <- read.csv(file=url('http://www.math.uah.edu/stat/data/HorseKicks.csv'),header=T)
summary(example)

hist(example$C14,prob=T)
summary(glm(C14~1,family=poisson(link='log'),data=example))
lines(x=0:4,y=dpois(0:4,lambda=exp(0.1823)),col='red',lwd=1)
Carla
  • 46
  • 5

1 Answers1

0

May be not that nice but for example like this:

library(ggplot2)

ggplot(example) + geom_histogram(aes(x = C14,y = ..density..),binwidth = 1) +
stat_function(fun = function(x) dpois(x,lambda=exp(0.1823)),
color = "red", size = 1, n = 5)
aschmsu
  • 302
  • 1
  • 9