Question

I have a adjacency list and I want to visualize them and do processing on it. Is there a package to do it efficiently. I see there are lot of graph packages but confused among them. Can someone help me on this?

$`825`
[1] 824

$`824`
[1] 823

$`823`
[1] 822

$`822`
[1] 821

$`821`
[1] 820 777

$`820`
[1] 819 816 789 787 785 783

$`777`
[1] 776

Above is the adjacency list. Below is the graph I want.

825
 |
824
 |          _______ 783
823        /
 |        /________ 785
822      /
 |      /__________ 787
821 -- 820
 |      \__________ 789
777      \
 |        \________ 816
776        \
            \______ 819

Thanks.

Was it helpful?

Solution

 mylist <- list(2,c(1,3),c(2,4),c(3,1))
 names(mylist) <- c(1,2,3,4)
 # just like your list

 #make it in the igraph format
 myadj <- stack(mylist)

#>    values ind
#>     1      2   1
#>     2      1   2
#>     3      3   2
#>     4      2   3
#>     5      4   3
#>     6      3   4
#>     7      1   4

 #plot it
 library(igraph)
 g<-graph.data.frame(myadj)
 plot(g)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top