2013-03-22 57 views
2

我有下面圖這個因子圖是用R繪製的嗎?

enter image description here

這些紅色箭頭表示加權係數,因爲它們都指向方向的每個節點。輸入文件是係數和方向的值。

這個因子圖是用R繪製的嗎?

+0

歡迎來到Stack Overflow!請提供樣本數據或可重複的示例,以便這裏的好人可以更好地幫助您。請參閱http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – 2013-03-22 03:35:30

+0

詳細的問題是,我有一個地質模型包含一些注水井和一個數字當然每個注入井都會有不同的係數(B)或對其他產油層的影響,所以上面的圖像說明了每個生產井每個注入井的這些因素。我會給這個程序提供的是B的值,井位置,我想繪製每個注入點的指向特定生產者的每個因素,其大小與B的值成正比。我希望我在這裏有足夠的理解。 – Athii 2013-03-22 06:25:17

回答

5

首先(我希望)一些虛擬數據效仿你(這是很難說考慮你給怎麼一點信息):

ow <- expand.grid(c(1.5,2.5),c(1.5,2.5)) 
row.names(ow)<-letters[1:4] 
pw <- expand.grid(1:3,1:3) 
row.names(pw)<-LETTERS[1:9] 
B <- rbind(expand.grid("a",row.names(pw)[c(1,2,4,5)]), 
      expand.grid("b",row.names(pw)[c(2,3,5,6)]), 
      expand.grid("c",row.names(pw)[c(4,5,7,8)]), 
      expand.grid("d",row.names(pw)[c(5,6,8,9)])) 
B <- cbind(B,abs(rnorm(16))) 

因此,我們有:

# The location of your oil wells: 
ow 
    Var1 Var2 
a 1.5 1.5 
b 2.5 1.5 
c 1.5 2.5 
d 2.5 2.5 
# Of your production wells: 
pw 
    Var1 Var2 
A 1 1 
B 2 1 
C 3 1 
D 1 2 
E 2 2 
F 3 2 
G 1 3 
H 2 3 
I 3 3 
#And a b value for each pairs of neighbouring oil/production wells: 
    Var1 Var2 abs(rnorm(16)) 
1  a A  1.78527757 
2  a B  1.61794028 
3  a D  1.80234599 
4  a E  0.04202002 
5  b B  0.90265280 
6  b C  1.05214769 
7  b E  0.67932237 
8  b F  0.11497430 
9  c D  0.26288589 
10 c E  0.50745137 
11 c G  0.74102529 
12 c H  1.43919338 
13 d E  1.04111278 
14 d F  0.49372216 
15 d H  0.21500663 
16 d I  0.20156929 

這裏是一個簡單的函數,或多或少地繪製您所展示的圖表類型:

weirdplot <- function(ow_loc, pw_loc, B, 
        pch_ow=19, pch_pw=17, 
        col_ow="green", col_pw="blue", col_b="red", breaks){ 
    # with ow_loc and pw_loc the locations of your wells 
    # B the correspondance table 
    # pch_ow and pch_pw the point type for the wells 
    # col_b, col_ow and col_pw the colors for the arrows and the wells 
    # and breaks a vector of size categories for b values 
    plot(pw_loc,type="n") 
    b<-cut(B[,3], breaks=breaks) 
    for(i in 1:nrow(B)){ 
     start=ow_loc[row.names(ow)==B[i,1],] 
     end=pw_loc[row.names(pw)==B[i,2],] 
     arrows(x0=start[,1],y0=start[,2], 
       x1=end[,1], y1=end[,2], lwd=b[i], col=col_b) 
     } 
    points(pw_loc, pch=pch_pw, col=col_pw) 
    points(ow_loc, pch=pch_ow, col=col_ow) 
    } 

因此,我們的值早期reated:

weirdplot(ow, pw, B, breaks=c(0,0.5,1,1.5,2)) 

enter image description here

這不是特別漂亮,但它應該讓你開始。