2

我有下图

在此处输入图像描述

这些红色箭头表示每个节点在它们指向的方向上的权重因子。输入文件是因子的值和方向。

这个因子图可以用 R 绘制吗?

4

1 回答 1

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)
    }

因此,使用我们之前创建的值:

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

在此处输入图像描述

它不是特别漂亮,但它应该让你开始。

于 2013-03-22T08:51:32.333 回答