【问题标题】:Density plot with ggplot [duplicate]ggplot的密度图[重复]
【发布时间】:2017-11-05 13:56:48
【问题描述】:

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

【问题讨论】:

    标签: r ggplot2


    【解决方案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)
    

    【讨论】:

      猜你喜欢
      • 2015-10-16
      • 1970-01-01
      • 1970-01-01
      • 2021-04-17
      • 2015-12-26
      • 2016-01-22
      • 2018-11-14
      • 2018-08-19
      • 1970-01-01
      相关资源
      最近更新 更多