【问题标题】:Plot multiple fitdist objects in same the plot with different colors?在同一图中用不同颜色绘制多个 fitdist 对象?
【发布时间】:2016-04-19 11:39:15
【问题描述】:

我有一个fitdist 对象列表,我使用这段代码存储了这些对象。

norm_dist_res <- list()
for(i in 1:10)
{
  x <- 1+(8000*(i-1))
  y <- 8000*i
  print (x)
  print(y)
  norm_dist_res[[i]] = norm_dist_res[[i]] <- fitdist(data=as.vector(g_all_p$data[x:y,]), distr="norm")

}

有没有办法用不同的颜色绘制从fittest 提取的所有正态分布以显示数据的分布情况?

或者一般来说如何可视化多个正态分布?

【问题讨论】:

  • fitdist 对象的内容是什么?此函数不是基础 R 的一部分。

标签: r plot normal-distribution fitdistrplus


【解决方案1】:

您正在估计正态分布的参数,因此只需绘制密度。

## Don't no what g_all_p is, so simplifying the data
library(fitdistrplus)
norm_dist_res <- list()
for(i in 1:10)
{
  norm_dist_res[[i]] = norm_dist_res[[i]] <- fitdist(data=rnorm(10), distr="norm")

}

然后使用lines 进行绘图并更改颜色

x = seq(-5, 5, length.out=100)
plot(x, type="n", ylim=c(0, 1), xlim=range(x))
for(i in 1:10) {
  est = norm_dist_res[[i]]$estimate
  lines(x, dnorm(x, est[1], est[2]), col="grey90")
}

得到

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-29
    • 1970-01-01
    • 2019-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-19
    • 1970-01-01
    相关资源
    最近更新 更多