1

I have following matrix and I want to draw overlapping graph using R (preferable) or Excel.

    a       b       c
a   1       0.5     0.7
b   0.5     1       0.4
c   0.7     0.4     1

For example, the above table shows that a and b have 50% overlapping, whereas a and c have 70%.

orftz
  • 1,138
  • 13
  • 22
user751637
  • 307
  • 1
  • 6
  • 16

1 Answers1

0

If you want overlapping then you missed one number - overlapping all three: a, b, c.

As Aniko write in comment you could use Venn diagrams, e.g. Vennerable from R-forge.

Installation need some packages from BioConductor:

source("http://bioconductor.org/biocLite.R")
biocLite(c("graph", "RBGL", "gtools", "xtable"))
install.packages("Vennerable", repos="http://R-Forge.R-project.org")

You mast prepare your data properly:

require(Vennerable)
x <- Venn(
    SetNames = c("a", "b", "c"),
    Weight = c(`100`=1,   `010`=1,   `001`=1,
               `110`=0.5, `101`=0.7, `011`=0.4,
               `111`=.5) # I made this up cause your question miss it
)

And voilà:

plot(x, doWeights=TRUE)

Venn diagram


Some additional explanations.

Data structures for Vennerable package need to provide set names ("a", "b", "c" in your case) and frequencies/proportions of each intersects. This 0/1 names identify subsets: 1 means "in set", 0 means "not in set". So e.g.:

  • 100 means in a, not in b, not in c,
  • 011 means not in a, in b, in c

So 111 means in all three sets, which is missing in your matrix and it can't be added there. For your sample data when a&b has 0.7 overlapping and b&c has 0.4 means that at least 0.1 is in three set at the same time (or I missed interpretation of this numbers). (note: I think I overestimated this 0.5, cause it should be lower than 0.4)

You could prepare your data to Venn plot before creating matrix, e.g:

X <- list(
    a = c("One", "Two", "Three"),
    b = c("One", "Three", "Four", "Five", "Seven"),
    c = c("Three", "Five", "Eight", "Nine", "Ten")
)

x <- Venn(X)
x
# A Venn object on 3 sets named
# a,b,c 
# 000 100 010 110 001 101 011 111 
#   0   1   2   1   3   0   1   1 
plot(x, doWeights=TRUE)
Marek
  • 49,472
  • 15
  • 99
  • 121
  • Thanks for your answer. Could you please explain little bit more that how did you mapped my matrix in your function? and why did you add another 0.5? Where can I put this number in my matrix? What are 101, 110, or 100 values? In addition, my values are 0.003,0.0047 etc. Will it create problems? – user751637 Jun 07 '11 at 01:50
  • @user751637 I add some explanations. Check it is answer your doubts. – Marek Jun 07 '11 at 12:12