2017-06-04 63 views
-1

我對數據集可視化的比較感興趣:直方圖和密度。我只使用下面的數據集作爲例子,但想法是一樣的,它是用於泊松分佈的: 任何人都可以幫我用ggplot2來繪製這個圖嗎?ggplot密度圖

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) 

回答

0

可能不是很好,但比如像這樣:

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)