R 密度图与ggplot
我对数据集的可视化比较感兴趣:直方图和密度。我仅以下面的数据集为例,但其思想是相同的,适用于泊松分布: 有人能帮我用ggplot2打印显示这个吗R 密度图与ggplot,r,ggplot2,R,Ggplot2,我对数据集的可视化比较感兴趣:直方图和密度。我仅以下面的数据集为例,但其思想是相同的,适用于泊松分布: 有人能帮我用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='l
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)
示例可能没有那么好,但例如:
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)