Hi,
It's not the call to plot() that complains that the rownames and colnames must be identical, it's your attempt at coercing your matrix to a graphNEL object. This coercion expects the input to be an adjacency matrix and in your case it's not, because its rownames and colnames are not the same.
Here is how you can generate the adjacency matrix:
> symptoms
Abdominal pain Chest pain Flu-like Liver Damage Nausea Numbness
Avandaia 1 0 0 1 1 1
Warfrin 0 1 1 0 1 1
Swelling
Avandaia 1
Warfrin 1
nodes <- unlist(dimnames(symptoms))
nb_nodes <- length(nodes)
edges <- which(symptoms == 1L, arr.ind=TRUE)
edges <- cbind(rownames(symptoms)[edges[,"row"]],
colnames(symptoms)[edges[,"col"]])
adjmat <- matrix(integer(nb_nodes^2), nrow=nb_nodes, dimnames=list(nodes, nodes))
adjmat[edges] <- 1L
Then:
> adjmat
Avandaia Warfrin Abdominal pain Chest pain Flu-like Liver Damage
Avandaia 0 0 1 0 0 1
Warfrin 0 0 0 1 1 0
Abdominal pain 0 0 0 0 0 0
Chest pain 0 0 0 0 0 0
Flu-like 0 0 0 0 0 0
Liver Damage 0 0 0 0 0 0
Nausea 0 0 0 0 0 0
Numbness 0 0 0 0 0 0
Swelling 0 0 0 0 0 0
Nausea Numbness Swelling
Avandaia 1 1 1
Warfrin 1 1 1
Abdominal pain 0 0 0
Chest pain 0 0 0
Flu-like 0 0 0
Liver Damage 0 0 0
Nausea 0 0 0
Numbness 0 0 0
Swelling 0 0 0
> library(graph)
> g1 <- as(adjmat, "graphNEL")
> g1
A graphNEL graph with directed edges
Number of Nodes = 9
Number of Edges = 10
> plot(g1, "neato")
Another option would be to call the graphNEL() constructor to make the graphNEL object:
g2 <- graphNEL(nodes, split(edges[, 2], edges[, 1]), edgemode="directed")
Unfortunately I get a segfault when trying to plot g2:
> plot(g2, "neato")
*** caught segfault ***
address 0x40000093, cause 'memory not mapped'
Traceback:
1: .Call("Rgraphviz_buildEdgeList", aa, edgemode(graph), subGList, edgeNames, removed, edgeAttrs, defAttrs, PACKAGE = "Rgraphviz")
2: buildEdgeList(graph, recipEdges, edgeAttrs, subGList, attrs$edge)
3: agopen(x, name = name, layout = TRUE, layoutType = y, attrs = attrs, nodeAttrs = nodeAttrs, edgeAttrs = edgeAttrs, subGList = subGList, recipEdges = recipEdges)
4: .local(x, y, ...)
5: plot(g2, "neato")
6: plot(g2, "neato")
Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace
Selection:
But that's another story and I'll leave it to the graph/Rgraphviz maintainers.
Cheers,
H.
> sessionInfo()
R version 3.1.2 (2014-10-31)
Platform: x86_64-unknown-linux-gnu (64-bit)
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] grid stats graphics grDevices utils datasets methods
[8] base
other attached packages:
[1] Rgraphviz_2.10.0 graph_1.44.0
loaded via a namespace (and not attached):
[1] BiocGenerics_0.12.1 parallel_3.1.2 stats4_3.1.2
[4] tools_3.1.2
Perfect, now that I know where I went wrong I feel like an idiot. Thanks James your solution was awesome.