Grace
Grace

Reputation: 201

How to resolve 'only connected graphs are supported' issue in ggraph in R?

I have a graph object, but when plotted using ggraph() using layout 'sparse_stress' (also tried other layouts), it is followed with the below error.

The min(degree) is 1. There are no disconnected nodes. What does the error mean by "only connected graphs are supported"?

Subgraph_1994 = asIgraph(Subgraph_1994)

#sparse-stress gives error
ggraph(Subgraph_1994_Rev,layout="sparse_stress") + geom_edge_link() + geom_node_point() + theme_graph()

#also tried below but same error
ggraph(Subgraph_1994) + geom_edge_link() + geom_node_point() + theme_graph()

Error Message

Error in layout_with_sparse_stress(graph, pivots = pivots, weights = weights, : only connected graphs are supported.

Upvotes: 1

Views: 1077

Answers (2)

panzerotti
panzerotti

Reputation: 33

Using the basic plot command will successfully plot a disconnected graph using the igraph plotting algorithms, so if you specify ggraph(Subgraph_1994, layout='igraph', algorithm='nicely') + ... then it should work even with disconnected graphs.

Upvotes: 0

krltrl
krltrl

Reputation: 60

Min(degree)=1 means there are no disconnected nodes indeed, but there still might be disconnected graphs. See the graphlayouts README on github

Setting layout="sparse" should fix your problem if the graph is not too big.

Upvotes: 1

Related Questions