# Separating disjoint sub-Graphs

Background: I am comparing the financial data from some 60 hospitals in The Netherlands over 2012 - 2017. The data are public, but need to be curated manually, as e.g. some hospitals have merged, some went (almost) broke. Further, there are irregularities in the original data sources.

I created a Graph with some 60 disjoint sub-Graphs. In each sub-Graph all the vertex labels should correspond to consecutive names+years: nameA2012, ..., nameA2017, and so on with nameB2012, ... . The idea is to check the vertex labels manually and make adjustments in the underlying data if necessary. However, it would be much easier to work on each disjoint sub-Graph separately.

How can I separate the various sub-Graphs as from this figure in separate Graphs?

Here are the data:

edges={1\[DirectedEdge]156,2\[DirectedEdge]82,3\[DirectedEdge]110,4\[DirectedEdge]101,5\[DirectedEdge]88,6\[DirectedEdge]105,7\[DirectedEdge]87,8\[DirectedEdge]89,9\[DirectedEdge]102,10\[DirectedEdge]120,11\[DirectedEdge]135,12\[DirectedEdge]111,13\[DirectedEdge]103,14\[DirectedEdge]104,15\[DirectedEdge]152,16\[DirectedEdge]134,17\[DirectedEdge]113,18\[DirectedEdge]124,19\[DirectedEdge]95,20\[DirectedEdge]86,21\[DirectedEdge]83,22\[DirectedEdge]84,23\[DirectedEdge]91,24\[DirectedEdge]107,25\[DirectedEdge]121,26\[DirectedEdge]137,27\[DirectedEdge]96,28\[DirectedEdge]98,29\[DirectedEdge]143,30\[DirectedEdge]125,31\[DirectedEdge]133,32\[DirectedEdge]136,33\[DirectedEdge]149,34\[DirectedEdge]131,35\[DirectedEdge]99,36\[DirectedEdge]93,37\[DirectedEdge]85,38\[DirectedEdge]127,39\[DirectedEdge]130,40\[DirectedEdge]160,41\[DirectedEdge]109,42\[DirectedEdge]159,43\[DirectedEdge]94,44\[DirectedEdge]129,45\[DirectedEdge]146,46\[DirectedEdge]128,47\[DirectedEdge]144,48\[DirectedEdge]114,49\[DirectedEdge]147,50\[DirectedEdge]109,51\[DirectedEdge]117,52\[DirectedEdge]119,53\[DirectedEdge]140,54\[DirectedEdge]142,55\[DirectedEdge]112,56\[DirectedEdge]100,57\[DirectedEdge]106,58\[DirectedEdge]154,59\[DirectedEdge]132,60\[DirectedEdge]126,61\[DirectedEdge]108,62\[DirectedEdge]115,63\[DirectedEdge]118,64\[DirectedEdge]92,65\[DirectedEdge]148,66\[DirectedEdge]138,67\[DirectedEdge]116,68\[DirectedEdge]157,69\[DirectedEdge]150,70\[DirectedEdge]139,71\[DirectedEdge]145,72\[DirectedEdge]97,73\[DirectedEdge]141,74\[DirectedEdge]158,75\[DirectedEdge]122,76\[DirectedEdge]123,77\[DirectedEdge]155,78\[DirectedEdge]151,79\[DirectedEdge]145,80\[DirectedEdge]153,81\[DirectedEdge]128,82\[DirectedEdge]161,83\[DirectedEdge]183,84\[DirectedEdge]191,85\[DirectedEdge]168,86\[DirectedEdge]185,87\[DirectedEdge]167,88\[DirectedEdge]197,89\[DirectedEdge]176,90\[DirectedEdge]171,91\[DirectedEdge]178,92\[DirectedEdge]181,93\[DirectedEdge]213,94\[DirectedEdge]190,95\[DirectedEdge]172,96\[DirectedEdge]190,97\[DirectedEdge]197,98\[DirectedEdge]162,99\[DirectedEdge]200,100\[DirectedEdge]211,101\[DirectedEdge]192,102\[DirectedEdge]197,103\[DirectedEdge]172,104\[DirectedEdge]166,105\[DirectedEdge]182,106\[DirectedEdge]185,107\[DirectedEdge]170,108\[DirectedEdge]186,109\[DirectedEdge]188,110\[DirectedEdge]198,111\[DirectedEdge]175,112\[DirectedEdge]194,113\[DirectedEdge]220,114\[DirectedEdge]179,115\[DirectedEdge]171,116\[DirectedEdge]162,117\[DirectedEdge]174,118\[DirectedEdge]166,119\[DirectedEdge]219,120\[DirectedEdge]204,121\[DirectedEdge]198,122\[DirectedEdge]169,123\[DirectedEdge]189,124\[DirectedEdge]203,125\[DirectedEdge]214,126\[DirectedEdge]206,127\[DirectedEdge]187,128\[DirectedEdge]169,129\[DirectedEdge]218,130\[DirectedEdge]165,131\[DirectedEdge]195,132\[DirectedEdge]184,133\[DirectedEdge]216,134\[DirectedEdge]217,135\[DirectedEdge]212,136\[DirectedEdge]196,137\[DirectedEdge]207,138\[DirectedEdge]213,139\[DirectedEdge]191,140\[DirectedEdge]173,141\[DirectedEdge]208,142\[DirectedEdge]180,143\[DirectedEdge]205,144\[DirectedEdge]221,145\[DirectedEdge]164,146\[DirectedEdge]161,147\[DirectedEdge]222,148\[DirectedEdge]224,149\[DirectedEdge]223,150\[DirectedEdge]210,151\[DirectedEdge]196,152\[DirectedEdge]228,153\[DirectedEdge]225,154\[DirectedEdge]226,155\[DirectedEdge]204,156\[DirectedEdge]209,157\[DirectedEdge]229,158\[DirectedEdge]227,159\[DirectedEdge]201,160\[DirectedEdge]230,161\[DirectedEdge]231,162\[DirectedEdge]235,163\[DirectedEdge]262,164\[DirectedEdge]249,165\[DirectedEdge]256,166\[DirectedEdge]267,167\[DirectedEdge]265,168\[DirectedEdge]248,169\[DirectedEdge]254,170\[DirectedEdge]236,171\[DirectedEdge]234,172\[DirectedEdge]252,173\[DirectedEdge]276,174\[DirectedEdge]259,175\[DirectedEdge]270,176\[DirectedEdge]246,177\[DirectedEdge]243,178\[DirectedEdge]288,179\[DirectedEdge]248,180\[DirectedEdge]268,181\[DirectedEdge]239,182\[DirectedEdge]258,183\[DirectedEdge]269,184\[DirectedEdge]238,185\[DirectedEdge]279,186\[DirectedEdge]263,187\[DirectedEdge]237,188\[DirectedEdge]247,189\[DirectedEdge]291,190\[DirectedEdge]242,191\[DirectedEdge]233,192\[DirectedEdge]266,193\[DirectedEdge]289,194\[DirectedEdge]259,195\[DirectedEdge]245,196\[DirectedEdge]244,197\[DirectedEdge]251,198\[DirectedEdge]260,199\[DirectedEdge]273,200\[DirectedEdge]285,201\[DirectedEdge]271,202\[DirectedEdge]272,203\[DirectedEdge]274,204\[DirectedEdge]261,205\[DirectedEdge]252,206\[DirectedEdge]277,207\[DirectedEdge]295,208\[DirectedEdge]257,209\[DirectedEdge]281,210\[DirectedEdge]282,211\[DirectedEdge]292,212\[DirectedEdge]240,213\[DirectedEdge]282,214\[DirectedEdge]278,215\[DirectedEdge]293,216\[DirectedEdge]280,217\[DirectedEdge]232,218\[DirectedEdge]236,219\[DirectedEdge]290,220\[DirectedEdge]250,221\[DirectedEdge]284,222\[DirectedEdge]298,223\[DirectedEdge]296,224\[DirectedEdge]299,225\[DirectedEdge]294,226\[DirectedEdge]286,227\[DirectedEdge]273,228\[DirectedEdge]287,229\[DirectedEdge]275,230\[DirectedEdge]255,231\[DirectedEdge]300,232\[DirectedEdge]305,233\[DirectedEdge]318,234\[DirectedEdge]308,235\[DirectedEdge]302,236\[DirectedEdge]313,237\[DirectedEdge]328,238\[DirectedEdge]303,239\[DirectedEdge]309,240\[DirectedEdge]331,241\[DirectedEdge]304,242\[DirectedEdge]306,243\[DirectedEdge]323,244\[DirectedEdge]356,245\[DirectedEdge]312,246\[DirectedEdge]301,247\[DirectedEdge]352,248\[DirectedEdge]320,249\[DirectedEdge]358,250\[DirectedEdge]336,251\[DirectedEdge]337,252\[DirectedEdge]330,253\[DirectedEdge]325,254\[DirectedEdge]311,255\[DirectedEdge]317,256\[DirectedEdge]327,257\[DirectedEdge]354,258\[DirectedEdge]348,259\[DirectedEdge]322,260\[DirectedEdge]334,261\[DirectedEdge]329,262\[DirectedEdge]335,263\[DirectedEdge]314,264\[DirectedEdge]347,265\[DirectedEdge]332,266\[DirectedEdge]343,267\[DirectedEdge]321,268\[DirectedEdge]326,269\[DirectedEdge]351,270\[DirectedEdge]344,271\[DirectedEdge]339,272\[DirectedEdge]311,273\[DirectedEdge]324,274\[DirectedEdge]355,275\[DirectedEdge]345,276\[DirectedEdge]350,277\[DirectedEdge]341,278\[DirectedEdge]357,279\[DirectedEdge]342,280\[DirectedEdge]353,281\[DirectedEdge]315,282\[DirectedEdge]349,283\[DirectedEdge]310,284\[DirectedEdge]333,285\[DirectedEdge]362,286\[DirectedEdge]354,287\[DirectedEdge]316,288\[DirectedEdge]326,289\[DirectedEdge]360,290\[DirectedEdge]343,291\[DirectedEdge]319,292\[DirectedEdge]307,293\[DirectedEdge]365,294\[DirectedEdge]363,295\[DirectedEdge]346,296\[DirectedEdge]361,297\[DirectedEdge]340,298\[DirectedEdge]364,299\[DirectedEdge]359,300\[DirectedEdge]368,301\[DirectedEdge]374,302\[DirectedEdge]367,303\[DirectedEdge]370,304\[DirectedEdge]375,305\[DirectedEdge]369,306\[DirectedEdge]372,307\[DirectedEdge]384,308\[DirectedEdge]366,309\[DirectedEdge]400,310\[DirectedEdge]392,311\[DirectedEdge]377,312\[DirectedEdge]371,313\[DirectedEdge]381,314\[DirectedEdge]395,315\[DirectedEdge]383,316\[DirectedEdge]388,317\[DirectedEdge]399,318\[DirectedEdge]380,319\[DirectedEdge]379,320\[DirectedEdge]390,321\[DirectedEdge]411,322\[DirectedEdge]373,323\[DirectedEdge]393,324\[DirectedEdge]385,325\[DirectedEdge]396,326\[DirectedEdge]391,327\[DirectedEdge]387,328\[DirectedEdge]417,329\[DirectedEdge]376,330\[DirectedEdge]403,331\[DirectedEdge]402,332\[DirectedEdge]407,333\[DirectedEdge]397,334\[DirectedEdge]416,335\[DirectedEdge]389,336\[DirectedEdge]424,337\[DirectedEdge]394,338\[DirectedEdge]408,339\[DirectedEdge]412,340\[DirectedEdge]382,341\[DirectedEdge]398,342\[DirectedEdge]405,343\[DirectedEdge]420,344\[DirectedEdge]407,345\[DirectedEdge]398,346\[DirectedEdge]400,347\[DirectedEdge]404,348\[DirectedEdge]386,349\[DirectedEdge]409,350\[DirectedEdge]418,351\[DirectedEdge]410,352\[DirectedEdge]414,353\[DirectedEdge]427,354\[DirectedEdge]406,355\[DirectedEdge]401,356\[DirectedEdge]421,357\[DirectedEdge]415,358\[DirectedEdge]419,359\[DirectedEdge]431,360\[DirectedEdge]423,361\[DirectedEdge]428,362\[DirectedEdge]426,363\[DirectedEdge]425,364\[DirectedEdge]422,365\[DirectedEdge]429};


Here is the code for making the above figure:

Graph[edges
,AspectRatio->1
,ImageSize->700
,VertexLabels->Automatic
]


You can use WeaklyConnectedGraphComponents on the input set edges:

WeaklyConnectedComponents returns a list of components $$\{c_1,c_2,\ldots\}$$, where each component $$c_i$$ is given as a graph.

wcgc = WeaklyConnectedGraphComponents[edges]

Length@wcgc


63

Grid[Partition[SetProperty[#, VertexLabels -> "Name"] & /@ wcgc, 7], Dividers -> All]


• +1 I must have overlooked this function. Thanks. – Romke Bontekoe Feb 4 '19 at 14:22

Does this help?

G = Graph[edges
,AspectRatio->1
,ImageSize->700
,VertexLabels->Automatic
];
Subgraph[G, #, VertexLabels -> "Name"] & /@ WeaklyConnectedComponents[G]

• +1 As above, I must have overlooked this one. Thanks. – Romke Bontekoe Feb 4 '19 at 14:24
• You're welcome! – Henrik Schumacher Feb 4 '19 at 14:26