I'm a first-time poster, but a long-time learner from this site. This is the first time an answer to my question hasn't been reverse-engineer-able from previous posts, so I'm hoping someone can help me solve it.
I'm trying to plot the results of a hill-climbing search algorithm (hc
from the bnlearn
package in R) run on a correlation matrix as a Reingold-Tilford tree graph.
Say I run:
hc.obj<-hc(corr.matrix)
hc.plot<-qgraph(hc.obj, directed = "TRUE", layout = "spring")
I get a Fruchterman-Reingold layout of the directed relationships no problem.
But I can't get a tree layout to work no matter how I format the information in hc.obj. For example, running the code above with "layout = tree" I get the error: "Error in l[, 1] : incorrect number of dimensions".
Here's a reproducible example:
require("bnlearn")
require("qgraph")
cm <- matrix(runif(100), ncol=10)
cm <- (cm * lower.tri(cm)) + t(cm * lower.tri(cm))
diag(cm) <- 1
cm.df<-as.data.frame(cm)
hc.obj<-hc(cm.df)
hc.plot<-qgraph(hc.obj, directed = "TRUE", layout = "tree")
Similarly, if I try to run through igraph as:
layout_as_tree(hc.obj)
I get the error "Error in layout_as_tree(hc.obj) : Not a graph object"