在具有不同颜色的绘图中绘制多个fitdist对象?

时间:2016-04-19 11:39:15

标签: r plot normal-distribution fitdistrplus

我有一个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提取的所有正态分布图,以显示数据的分布方式?

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

1 个答案:

答案 0 :(得分: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")
}

获得

enter image description here