Given the following code:
ClearAll[names, vl, el, ew, community, vName, vRule, g, evc];
names = {
"agr: Agriculture, hunting, forestry, fishing",
"min: Mining and quarrying", "ma1: Food, beverages, tobacco",
"ma2: Textiles, textile products",
"ma3: Leather, leather products, footwear",
"ma4: Wood & products of wood and cork",
"ma5: Pulp, paper, paper products, printing, publishing",
"ma6: Coke, refined petroleum, nuclear fuel",
"ma7: Chemicals & chemical products",
"ma8: Rubber-plastics products",
"ma9: Other non-metallic mineral products",
"ma10: Manufacture of basic metals",
"ma11: Machinery-equipment n.e.c", "ma12: Electrical
equipment", "ma13: Transport equipment", "ma14:
Manufacturing, nec; recycling", "segw: Electricity, gas,
water supply", "scst: Construction", "ma15: Sale-maintenance;
repair-install. of mach. equip.", "swhl: Wholesale trade,
except motor vehicles",
"srtl: Retail trade, except of motor vehicles",
"shot: Hotels & restaurants", "str1: Inland transport",
"str2: Water transport", "str3: Air transport",
"str4: Other supporting-transport act. of travel agencies",
"stel: Post & telecommunications",
"sfin: Financial intermediation", "sest: Real estate activities", "sbus: Renting of M&Eq and other business activities",
"sadm: Public adm.-defence;compulsory social security",
"sedu: Education", "shlt: Human health-social work",
"soth: Other community, social & personal services"
};
vl = {"stel", "segw", "ma7", "str1", "str3", "str2", "swhl", "sest",
"min", "sfin", "scst", "ma12", "shot", "ma8", "soth", "srtl",
"ma15", "ma6", "str4", "sbus", "ma13"};
el = {
"stel" \[DirectedEdge] "segw", "stel" \[DirectedEdge]"ma7",
"segw" \[DirectedEdge] "stel", "segw" \[DirectedEdge] "str1",
"segw" \[DirectedEdge] "str3", "segw" \[DirectedEdge] "str2",
"swhl" \[DirectedEdge] "stel", "swhl" \[DirectedEdge] "sest",
"swhl" \[DirectedEdge] "min", "swhl" \[DirectedEdge] "sfin",
"scst" \[DirectedEdge] "segw", "scst" \[DirectedEdge] "ma12",
"scst" \[DirectedEdge] "shot", "scst" \[DirectedEdge] "ma8",
"scst" \[DirectedEdge] "ma7", "scst" \[DirectedEdge] "soth",
"srtl" \[DirectedEdge] "segw", "srtl" \[DirectedEdge] "swhl",
"srtl" \[DirectedEdge] "ma15", "srtl" \[DirectedEdge] "ma6",
"str1" \[DirectedEdge] "segw", "str1" \[DirectedEdge] "str4",
"str1" \[DirectedEdge] "sbus", "str1" \[DirectedEdge] "str3",
"str1" \[DirectedEdge] "str2", "str1" \[DirectedEdge] "ma7",
"sest" \[DirectedEdge] "swhl", "sest" \[DirectedEdge] "srtl",
"ma12" \[DirectedEdge] "scst", "ma12" \[DirectedEdge] "ma15",
"ma12" \[DirectedEdge] "soth", "shot" \[DirectedEdge] "scst",
"str4" \[DirectedEdge] "scst", "str4" \[DirectedEdge] "ma12",
"ma15" \[DirectedEdge] "srtl", "ma15" \[DirectedEdge] "shot",
"ma15" \[DirectedEdge] "str4", "ma15" \[DirectedEdge] "ma8",
"ma15" \[DirectedEdge] "str3", "ma15" \[DirectedEdge] "str2",
"ma8" \[DirectedEdge] "str1", "ma8" \[DirectedEdge] "str3",
"min" \[DirectedEdge] "sest", "min" \[DirectedEdge] "soth",
"sbus" \[DirectedEdge] "sest", "sfin" \[DirectedEdge] "shot",
"sfin" \[DirectedEdge] "ma6", "ma6" \[DirectedEdge] "ma8",
"ma6" \[DirectedEdge] "min", "ma6" \[DirectedEdge] "ma13",
"str3" \[DirectedEdge] "sbus", "str3" \[DirectedEdge] "str2",
"ma13" \[DirectedEdge] "str3", "str2" \[DirectedEdge] "str3",
"ma7" \[DirectedEdge] "ma13", "soth" \[DirectedEdge] "ma7"};
ew = {0.01313, 0.0139, 0.0131, 0.0188, 0.01145, 0.01842,
0.01786,0.01203, 0.0137, 0.0188, 0.018, 0.01561, 0.01544,
0.01767, 0.0174, 0.0133, 0.0184, 0.0126, 0.01724, 0.0126,
0.0139, 0.010414`, 0.0169, 0.01498, 0.01736, 0.01832, 0.01211,
0.011911, 0.01586`, 0.01863, 0.01653, 0.01533, 0.0129, 0.0121,
0.01144, 0.014, 0.01109, 0.0172, 0.01267, 0.0171, 0.0150,
0.01192, 0.01428, 0.017406, 0.0109,
0.017892, 0.01338, 0.017794, 0.01095, 0.0187, 0.0155, 0.0142,
0.01422, 0.01125, 0.015559, 0.01788};
community = {{"stel", "segw", "str1", "str3", "str2", "sbus"},
{"ma7", "scst", "ma12", "shot", "soth", "str4"}, {"ma8", "srtl",
"ma15", "ma6", "ma13"}, {"swhl", "sest", "min", "sfin"}};
vName = Lookup[Flatten@community]@
MapApply[Rule]@StringSplit[names, ": "];
vRule = Thread[Flatten[community] -> vName];
g = Graph[vl, el, EdgeWeight -> ew];
ccoord =CirclePoints[{1, 0},
Length[vl]][[Ordering[VertexIndex[g, Flatten[community]]]]];
hg = HighlightGraph[
g,
Subgraph[g, #] & /@ community,
VertexCoordinates -> ccoord,
VertexLabels -> Placed["Name", "Circular"],
EdgeShapeFunction -> (Arrow[
BSplineCurve[{#[[1]], {0, 0}, #[[-1]]},
SplineWeights -> {1, EuclideanDistance[#[[1]], #[[-1]]]/10,
1}]] &), GraphHighlightStyle -> "DehighlightHide",
VertexShapeFunction -> "Circle"
];
lp = ListPlot[Callout @@@
Transpose[{GraphEmbedding[hg], VertexList[hg] /. vRule}],
Axes -> False, PlotStyle -> None];
Show[hg, lp]
Relevant posts in the MMA repository are
from https://mathematica.stackexchange.com/a/290654/60365 by @halmir
from https://mathematica.stackexchange.com/a/140885/60365 by @kglr
The directed graph produced is:
I want to produce the directed graph with the vertex long names, not with vertex short names such as stel
. As you can see from the following graph, Callout
is not working properly.
I like to use Callout
with long vertex names placed on the right and left sides of the graph vertically.