library(Rgraphviz)
set.seed(123)
V = letters[1:10]
M = 1:4
g1 = randomGraph(V, M, 0.2)
g1
plot(g1)
z = agopen(g1, "foo")
#agwrite(z, file="./R/R Books/MicroArray/g1.dot")

plot(g1, "neato")
print(isConnected(g1))

set.seed(123)
V = letters[14:22]
g2 = randomEGraph(V, 0.2)
print(isConnected(g2))
plot(g2, "twopi")

plot(g2, "dot")
plot(g2, "neato")

rEG = new("graphNEL", nodes=c("A", "B"), edgemode = "directed")
rEG = addEdge("A", "B", rEG, 1)
rEG = addEdge("B", "A", rEG, 1)
plot(rEG)
plot(rEG, recipEdges="distinct")
a = removedEdges(g1)
a

sg1=subGraph(c("a", "d", "j", "i"), g1)
sg1
sg2=subGraph(c("b", "e", "h"), g1)
sg2
sg3=subGraph(c("c", "f", "g"), g1)
sg3
subGList = vector(mode="list", length=3)
subGList[[1]] = list(graph=sg1)
subGList[[2]] = list(graph=sg2)
subGList[[3]] = list(graph=sg3)
plot(g1, subGList=subGList)

sg1=subGraph(c("a", "c", "d", "e", "j"), g1)
sg2=subGraph(c("f", "h", "i"), g1)
plot(g1, subGList=list(list(graph=sg1), list(graph=sg2)))

edgeNames(g1)
edgeNames(g1, recipEdges="distinct")

defAttrs=getDefaultAttrs()
defAttrs

plot(g1, attrs=list(node=list(label="foo", fillcolor="lightgreen"), edge=list(color="cyan"), graph=list(rankdir="LR")))

nAttrs=list()
eAttrs=list()

nAttrs$label=c(a="lab1", b="lab2", c="lab3", d="lab4")
eAttrs$label=c("a~h"="test", "c~h"="test2")
plot(g1, nodeAttrs=nAttrs, edgeAttrs= eAttrs)

