# How to plot a graph with some disconnected vertices?

I am trying to plot a graph with $6$ vertices but I do not want some of the vertices to be connected. I have drawn a picture to illustrate my problem.

So far I know how to plot $6$ vertices without edges at all. The command is

GraphPlot[Table[1, {6}, {6}], EdgeRenderingFunction -> None]


But I cannot figure out how to connect some of the vertices, not all.

I would really appreciate if you can suggest a way how to plot such a graph.

Graph[Range@10, {1 -> 2, 2 -> 3, 3 -> 1}]


• Hi, thank you very much for your answer, it is very helpful. But could you suggest how to move the disconnected vertices to different positions (i.e. to the right or left of the remaining connected subgraph)? I haved tried changing the vertex label but didn't do anything. Again, thank you. – johnny09 Oct 29 '15 at 19:06
• @johnny09 take a look at VertexCoordinates – Dr. belisarius Oct 29 '15 at 19:19

Belisarius already showed how to build a graph with unconnected vertices, and you asked about their positioning.

If you prefer a different arrangement of the unconnected vertices (or the connected components in general), take a look at the "PackingLayout" suboption of GraphLayout. The documentation has examples.

Mathematica is smart about graph layouts: it first breaks the graph into connected components, then lays out each component separately, then tries to align each horizontally, finally it packs the components together in a nice way. How exactly it does it is controlled by GraphLayout.

Sometimes one might want the result of a dumb layout algorithm that doesn't break the graph into components before performing the layout algorithm. If you want this, take a look at IGraph/M, which will give results similar to this:

<< IGraphM

IGLayoutFruchtermanReingold@RandomGraph[{100, 80}]


Unfortunately most other layout algorithms it provides might get upset when they see disconnected vertices, and place them in unpleasant locations ... but the Furchterman–Reingold (same as "SpringElectricaEmbedding" in Mathematica) tends to give nice results.

IGLayoutKamadaKawai@RandomGraph[{100, 80}]


IGLayoutDavidsonHarel@RandomGraph[{100, 80}]
`