2016-04-19 62 views
0

我有一个使用这段代码存储的fitdist对象列表。在不同颜色的情节中绘制多个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用不同的颜色来显示数据的分布中提取的正态分布?

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

+0

什么是'fitdist'对象的内容?这个函数不是基R的一部分。 – lmo

回答

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

相关问题