I need to visualize a graph spatially, and I'm simply using:
HighlightGraph[ConnectedGraphComponents[]]
and the known coordinates of the graph's nodes. I really like how it looks, but for large graphs, I'd like to delete those edges at the "boundaries" of the spatial domain (a square grid of known side length). By the method I generate the graphs, all edges are always 1 space unit of distance from other nodes, so they look good, but edges joining extreme nodes (still 1 unit in periodic boundary conditions) traverse the whole grid in the visualization, and it can look messy for large graphs.
If I could use the information of the grid size to omit the visualization of edges that join "boundary" nodes, that would be great. I just don't know where to start.
Here's a Dummy example of what I'm talking about:
(*Imagine the spatial domain is a square of side 4*)
(*Create the graph*)
DummyGraph = Graph[{a <-> b, c <-> d, e <-> f}];
(*Let's assume these are the coordinates of the {a,b,c,d,e,f} nodes*)
DummyCoordinates = {{1, 1}, {4, 1}, {2, 1}, {2, 4}, {3, 2}, {3, 3}};
(*Then we can get a nice "spatial" visualization of this graph*)
HighlightGraph[
DummyGraph, ConnectedGraphComponents[DummyGraph],
VertexCoordinates -> DummyCoordinates,
VertexSize -> .85, VertexShapeFunction -> "RoundedSquare",
VertexLabelStyle -> Directive[Bold, 25],
VertexLabels -> "Name",
Background -> "White"
]
Note that the edges joining a<->b
and c<->d
are long because they need to traverse the whole grid (in this dummy example the grid side is 4). What I'd like to preserve is their respective colors (because I need to distinguish them, as in ConnectedGraphComponents[]
) but omit the drawing of this particular edges, while keeping all other edges (for instance, I'd like to keep f<->e
).
I've thought of something like getting a list with all those edges that join two "boundary" nodes, and then somehow (in the options of EdgeShapeFunction[]
perhaps?) make them "transparent" while keeping the information on ConnectedGraphComponents[]
and the visualization of all the other edges. But haven't found options to omit specific subset of edges in the visualization using HighlightGraph[ConnectedGraphComponents[]]
. I've also found this answer, and it might be useful, but in my case, all edges have the same weights, so I'm not sure if that process is directly applicable to my case.
Thanks in advance for any help/suggestion,
Pedro
Notes: 1) I don't want to delete those edges from the graph object (since HighlightGraph[]
wouldn't work with ConnectedGraphComponents[]
anymore, as a single component would be split into many, and thus the color visualization would change). This is just a visualization problem I'm trying to solve. 2) I've checked IGraph/M
to see if there's something about this, but I couldn't find a clear direction. 3) Just to show why I want to avoid those "long edges", here's one of the visualizations in which those "long edges" go through many other ConnectedGraphComponents[]
.
EDIT 1:
The answer below by @kglr is a great start, and I'll explore it further, but perhaps I wasn't clear in that I'd like to keep any other edge that does not traverse the whole grid. Using @kglr answer on large graphs, I see that any edge that belongs to a "boundary node" is removed, even when many of these edges would not traverse the whole grid. Here, for instance, I zoom in into nodes that should be joined by edges (i.e. they belong to the same GraphComponent
) but are filtered out: