2

I have the below diagram

enter image description here

These red arrows represent weighting factors for each node in the direction that they are pointing to. The input file is the value of the factor and the direction.

Is this factors diagram plottable with R?

Nikita Volkov
  • 42,792
  • 11
  • 94
  • 169
Athii
  • 130
  • 2
  • 11
  • Welcome to Stack Overflow! Please give sample data or reproducible example so that good people here can help you better. See http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – CHP Mar 22 '13 at 03:35
  • The problem in details is that I have a geological model contains a number of water injection wells and a number of oil producing wells, and of course each injection well will have a different coefficient (B) or impact on the other oil producers, so the above image illustrates these factors for each injection well on each production well. what I will feed the program is the values of the B's, the wells locations and I want to plot each factor form each injector pointing to the specific producer in a size proportional to the value of B..I wish I made enough sense here. – Athii Mar 22 '13 at 06:25

1 Answers1

5

First some dummy data which (I hope) emulate yours (which is hard to say considering how little information you gave):

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

So we have:

# 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

And here is a simple function that plot more or less the kind of graph you showed:

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

So with the values we created earlier:

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

enter image description here

It's not particularly pretty but it should get you started.

plannapus
  • 18,529
  • 4
  • 72
  • 94