Search code examples
plotgraphigraphggraph

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.


Solution

  • 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.