Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 密度图与ggplot_R_Ggplot2 - Fatal编程技术网

R 密度图与ggplot

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

我对数据集的可视化比较感兴趣:直方图和密度。我仅以下面的数据集为例,但其思想是相同的,适用于泊松分布: 有人能帮我用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)

示例可能没有那么好,但例如:

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)