2013-02-24 92 views
4

我试图使用包poweRlaw绘制一些powerlaw适合。它似乎适用于单曲线。但我无法在同一个图上绘制多个图。 Ref:这个包里有没有办法? [P.S.我是新手]多个幂律图与包PoweRlaw

set.seed(1) 
x1 <- ceiling(rlnorm(1000, 4)) 

x2 <- ceiling(rlnorm(1000, 2)) 

library(poweRlaw) 

pl_d = pl_data$new(x1) 
plot(pl_d) 

#Now fit the powerlaw 
m = displ$new(pl_d) 
#Estimate the cut-off 
#estimate_xmin(m) 
aaa <- estimate_xmin(m) 
aaa <- as.data.frame(aaa) 
aaa <- aaa[2,1] 
x_min <- min(table(x)) 
m$setXmin(aaa); m$mle() 
#Plot the data and the PL line 
#plot(m) 
lines(m, col=2) 

# next POWER LAW graph 

#Plot the data 
pl_d = pl_data$new(x2) 
points(pl_d) 

#Now fit the powerlaw 
m = displ$new(pl_d) 
#Estimate the cut-off 
#estimate_xmin(m) 
aaa <- estimate_xmin(m) 
aaa <- as.data.frame(aaa) 
aaa <- aaa[2,1] 
x_min <- min(table(x)) 
m$setXmin(aaa); m$mle() 
#Plot the data and the PL line 
#points(m) 
lines(m, col=3) 

回答

3

您可以使用lines命令添加多个最佳拟合幂律。因此,使用你的数据:

set.seed(1) 
x1 = ceiling(rlnorm(1000, 4)) 

我们加载包并创建一个独立的幂律对象:

m = displ$new(x1) 

然后绘制数据

plot(m) 

接下来,我们设置xminalpha为每个幂律,并将其添加到图形使用lines

m$setXmin(100) 
p_100 = estimate_pars(m) 
m$setPars(p_100) 
lines(m, col=2, lwd=2) 

##Line 2  
m$setXmin(202) 
p_200 = estimate_pars(m) 
m$setPars(p_200) 
lines(m, col=3, lwd=2) 

enter image description here


如果你想对同积多个数据集,最简单的方法是画出一个数据集,但数据保存为一个数据帧。例如,生成一些数据集:

set.seed(1) 
x1 = ceiling(rlnorm(1000, 4)) 
x2 = ceiling(rlnorm(1000, 5)) 

适合的幂律

m1 = displ$new(x1) 
m1$setXmin(estimate_xmin(m1)) 

m2 = displ$new(x2) 
m2$setXmin(estimate_xmin(m2)) 

情节数据集2,但数据保存为pts2

pts2 = plot(m2) 

情节,并添加行作为正常:

plot(m1) 
points(pts2$x, pts2$y, col=3) 
lines(m1, col=2) 
lines(m2, col=4) 

得到:

enter image description here

+0

谢谢。将等待不同的“xmins”版本。 – 2013-02-26 01:35:18

+0

那么,我真正想要绘制的是类似以下内容: ![FIGURE] 2013-03-28 14:34:19

+0

@AttuD查看更新后的答案。在将来的版本中,我可能会为plot函数添加一个参数以使其更容易。 – csgillespie 2013-03-28 21:06:18