2013-02-24 69 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