-1

I want to have a venn diagram of the differences in two matrices p.mat.p and p.mat.t which have same dimensions when alpha set. Pseudocode

  1. add item to the intersection if matches between two matrices; it can be match FALSE or TRUE; else leave the item outside the intersection like normally with Venn diagrams
  2. Put IDs of matrix cells on the Venn diagram

Two approaches: matrix with vennDiagram and venn with lists. Data

p.mat.p
           1     2     3     4     5     6     7     8     9    10    11
    1   TRUE  TRUE  TRUE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE
    2   TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
    3   TRUE  TRUE  TRUE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE
    4  FALSE FALSE FALSE  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE
    5  FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE
    6   TRUE FALSE  TRUE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE
    7  FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE
    8  FALSE FALSE FALSE  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE
    9  FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE
    10 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE
    11 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE

p.mat.t
           1     2     3     4     5     6     7     8     9    10    11
    1  FALSE  TRUE  TRUE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE  TRUE
    2   TRUE FALSE FALSE FALSE  TRUE FALSE  TRUE  TRUE  TRUE  TRUE FALSE
    3   TRUE FALSE FALSE FALSE  TRUE FALSE  TRUE  TRUE  TRUE  TRUE FALSE
    4   TRUE FALSE FALSE FALSE  TRUE FALSE  TRUE  TRUE  TRUE  TRUE FALSE
    5  FALSE  TRUE  TRUE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE  TRUE
    6   TRUE FALSE FALSE FALSE  TRUE FALSE  TRUE  TRUE  TRUE  TRUE FALSE
    7  FALSE  TRUE  TRUE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE  TRUE
    8  FALSE  TRUE  TRUE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE  TRUE
    9  FALSE  TRUE  TRUE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE  TRUE
    10 FALSE  TRUE  TRUE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE  TRUE
    11  TRUE FALSE FALSE FALSE  TRUE FALSE  TRUE  TRUE  TRUE  TRUE FALSE

Code with matrices

library("psych")
library("gplots")
library("limma") # http://www.ats.ucla.edu/stat/r/faq/venn.htm       

ids <- seq(1,11)
M.cor <- cor(mtcars)
colnames(M.cor) <- ids
rownames(M.cor) <- ids
p.mat <- psych::corr.test(M.cor, adjust = "none", ci = F)

alpha <- .00000005

p.mat.p <- (p.mat[["p"]] < alpha)
str(p.mat.p)
print(p.mat.p)

p.mat.t <- (p.mat[["t"]] < alpha)
str(p.mat.t)
print(p.mat.t)

# http://www.ats.ucla.edu/stat/r/faq/venn.htm
c3 <- cbind( c(p.mat.p), c(p.mat.t))
a <- vennCounts(c3)
vennDiagram(a)

Output without IDs on circles and its intersection so not sufficient

enter image description here

Expected output: venn diagram with IDs on intersection, circles and elsewhere.

With lists

I think working with lists is mandatory here because venn supports only them

library("corrplot")
library("psych")

ids <- seq(1,11)
M.cor <- cor(mtcars)
colnames(M.cor) <- ids
rownames(M.cor) <- ids
p.mat <- psych::corr.test(M.cor, adjust = "none", ci = F)

alpha <- .00000005

# http://stackoverflow.com/q/2471188/54964
p.mat.p <- (p.mat[["p"]] < alpha)
p.mat.p <- as.list(p.mat.p)

p.mat.t <- (p.mat[["t"]] < alpha)
p.mat.t <- as.list(p.mat.t)

venn(list(first.vector = p.mat.p, second.vector = p.mat.t))

Output: 121 in the intersection so wrong

R: 3.3.1
OS: Debian 8.5

Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697
  • 2
    Seems that you don't actually know how to describe what you want. – IRTFM Nov 12 '16 at 16:54
  • Distribution in matrices? And you only display the upper triangular elements. Right, how _could_ you be any more clear???? – IRTFM Nov 13 '16 at 06:53
  • Where do you import the vennCounts and vennDiagram? `'> a <- vennCounts(c3) Error: could not find function "vennCounts" > vennDiagram(a) Error: could not find function "vennDiagram"'` – hhh Nov 13 '16 at 21:08
  • @Masi `"package ‘limma’ is not available (for R version 3.3.2)"`, notice that limma is getting depreciated already in 3.3.2 -- cannot get this working here unfortunately. – hhh Nov 13 '16 at 21:16
  • 1
    @hhh It is. Please, follow instructions exactly here http://www.ats.ucla.edu/stat/r/faq/venn.htm – Léo Léopold Hertz 준영 Nov 13 '16 at 21:16

1 Answers1

1

MATRIX_1 == MATRIX_2 gives you the differences between the matrices. Do print(p.mat.p == p.mat.t) and you get where TRUEs are items for the intersection and others; however, this will not work well with more than two matrices

       1     2     3     4     5     6     7     8     9    10    11
1  FALSE  TRUE  TRUE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE
2   TRUE FALSE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE  TRUE
3   TRUE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE
4  FALSE  TRUE  TRUE FALSE FALSE  TRUE FALSE  TRUE FALSE FALSE  TRUE
5   TRUE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE  TRUE FALSE
6   TRUE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE
7   TRUE FALSE FALSE FALSE  TRUE FALSE FALSE  TRUE  TRUE  TRUE FALSE
8   TRUE FALSE FALSE  TRUE  TRUE FALSE  TRUE FALSE  TRUE  TRUE FALSE
9   TRUE FALSE FALSE FALSE  TRUE FALSE  TRUE  TRUE FALSE  TRUE FALSE
10  TRUE FALSE FALSE FALSE  TRUE FALSE  TRUE  TRUE  TRUE FALSE FALSE
11 FALSE  TRUE  TRUE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE
Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697
hhh
  • 50,788
  • 62
  • 179
  • 282
  • I updated your body. I think this will not work well if you have more than two matrices. I am also not sure if you can create a venn diagram based on the result. - - First step to try it would be - get all points where true from the matrix, put them to the intersection; put `total - intersections` to the other two parts of the venn diagram. - - I think there must be something more direct in R to create a venn diagram from a list or matrix. – Léo Léopold Hertz 준영 Nov 13 '16 at 19:17