I have created Term Document matrix from a corpus:
x  <-  TermDocumentMatrix (corpus ) 
Then I created a matrix:
Matrix <- as.matrix ( x )
Matrix [ Matrix >=1 ] <- 1
Matrix <- tcrossprod ( Matrix )
As an output: `
                     Terms
              Terms  best  love fun don’t games
               best   31     0   1    2     0
               love    0     48  1    2     6
               fun     1     1   39   1     1
               dont    2     2   1   46     7
               games   0     6   1    7     54
Then I created a graph:
G <- graph.adjacency(Matrix, mode = "directed", weighted = TRUE)
Then used the STR function to check the graph object structure and the result are as follows:
Str(G)
    IGRAPH DNW- 25 452 -- 
    + attr: name (v/c), weight (e/n)
    + edges (vertex names):
    1 -> 3, 4, 6, 7, 8, 11, 14, 15, 20, 21, 23, 24
    2 -> 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 19, 20, 21, 22, 24, 25
    3 -> 1, 2, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 22, 24, 25
    4 -> 1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16, 17, 18, 19, 21,       
    5 -> 2, 3, 4, 7, 8, 9, 10, 11, 12, 13, 14, 17, 18, 20, 21, 22, 23, 24, 25
The problem is the “+ edges (vertex names)”. What I want is results below from a graph that I created for a different problem.
IGRAPH DNW- 20 31 -- 
+ attr: name (v/c), weight (e/n)
+ edges (vertex names):
[1] 1 ->2  1 ->3  1 ->5  2 ->4 
[5] 2 ->5  3 ->6  3 ->9  4 ->8 
[9] 5 ->7  5 ->20 6 ->9  7 ->8 
[13] 7 ->9  8 ->9  9 ->10 10->11
[17] 10->15 20->1  11->12 11->13
 
    
