# Axes Labeling in Bar Charts

How do I label a bar chart such that a list produced by Mathematica such as {{7, 0.0446108}, {5, 0.074924}, {2, 0.0778787}, {3, 0.0778787}, {1, 0.0798332}, {9, 0.0805987}, {10, 0.0805987}, {e, 0.0821453}, {8, 0.11312}, {4, 0.14265}, {6, 0.145762}} has the bar chart labeled from smallest to largest bar with numbers 7,5,2,3,1,9,10,e,8,4,6 appear in that order from left to right on the horizontal axis with the heights of the bars, e.g., 0.0778787 along the vertical axes.

Clear[AA, BB]
edges = {1 <-> 2, 1 <-> 3, 2 <-> 4, 3 <-> 4, 4 <-> 5, 4 <-> 6,
5 <-> 6, 7 <-> 6, 6 <-> 8, 8 <-> 9, 8 <-> 10, 9 <-> e, 10 <-> e};
AA = PageRankCentrality[edges]
BB = Sort[AA]
SortBy[{VertexList[edges],
PageRankCentrality[edges]}\[Transpose], Last]
PieChart[BB, ChartStyle -> "DarkRainbow", ChartLabels -> Automatic];
BarChart[BB, ChartStyle -> "DarkRainbow", ChartLabels -> Automatic]


edges = {1 <-> 2, 1 <-> 3, 2 <-> 4, 3 <-> 4, 4 <-> 5, 4 <-> 6,
5 <-> 6, 7 <-> 6, 6 <-> 8, 8 <-> 9, 8 <-> 10, 9 <-> e, 10 <-> e};
prc = PageRankCentrality[edges]


{0.0798,0.0778,0.0778,0.1426,0.0749,0.1457,0.04461,0.1131,0.08059,0.08059,0.08214}

ordering = Ordering @ prc;


GraphPropertyChart

GraphComputationGraphPropertyChart gives a layout that combines a pie chart of vertex properties with a graph of edges:

gpc = GraphComputationGraphPropertyChart[
Graph[VertexList[edges][[ordering]], edges],
Automatic -> prc[[ordering]], EdgeStyle -> Directive[CapForm["Butt"], Thickness[.05]],
ChartStyle->"DarkRainbow"]


Click on a vertex to get the incident edges highlighted:

Or use the function explode from this answer by Simon Woods to highlight incident edges for selected vertices:

explode[pc_, i_] := ReplacePart[pc, Position[pc, False][[i]] -> True]
explode[gpc, VertexIndex[g, #] & /@ {10,3, 6}]


GraphComputationGraphPropertyChart[Graph[VertexList[edges][[ordering]], edges],
Automatic -> prc[[ordering]],
ChartElementFunction -> ChartElementDataFunction["NoiseSector",
"AngularFrequency" -> 5, "RadialAmplitude" -> .2],
ChartLabels -> (Style[#, 16] & /@ VertexList[edges][[ordering]]), ChartStyle -> 63] /.
{False -> True , Text[x_, pos_] :> {FaceForm[White], Disk[pos, .7], Text[x, pos]}}


With a different ChartElementFunction:

ChartElementFunction -> ChartElementDataFunction["TriangleWaveSector",
"AngularFrequency" -> 10, "RadialAmplitude" -> .5]


GraphComputationGraphPropertyChart[Graph[edges],
Automatic -> ConstantArray[1, VertexCount[edges]],
EdgeStyle -> Directive[CapForm["Butt"], Thickness[.05]]]


bwc = BetweennessCentrality[Graph[edges]];
GraphComputationGraphPropertyChart[
Graph[VertexList[edges][[Ordering[bwc]]], edges], Automatic -> Sort[bwc],
EdgeStyle -> Directive[CapForm["Butt"], Thickness[.05]]]


PieChart

PieChart[prc[[ordering]], ChartStyle -> "DarkRainbow",
SectorOrigin -> {{2 Pi, "Counterclockwise"}, 1},
ChartLabels -> Placed[Style[#, 16] & /@ VertexList[edges][[ordering]], "RadialCallout"]]


BarChart

BarChart[prc[[ordering]], ChartStyle -> "DarkRainbow",
ChartLabels -> VertexList[edges][[ordering]]]


Update: Combining BarChart with Graph to produce something similar to the output of GraphPropertyChart:

gr1 = Graph[VertexList[edges][[ordering]], edges];
graph = SetProperty[gr1,
{ImageSize -> 500, GraphLayout -> {"LinearEmbedding", Method -> "SpectralOrdering"},

bc = BarChart[20 prc[[ordering]],
ChartLabels -> Placed[Style[#, 20] & /@ VertexList[gr1], Top],
ChartStyle -> "DarkRainbow", BarSpacing -> .2, BarOrigin -> Top,
Axes -> False, PerformanceGoal -> "Speed", ImageSize -> 500];
Show[bc, graph]


data = SortBy[{VertexList[edges],PageRankCentrality[edges]}\[Transpose], N@*Last]
BarChart[BB, ChartStyle -> "DarkRainbow",ChartLabels -> First /@ data]

• Alan ... Many thanks for your quick and very helpful response ... prg Commented May 3, 2017 at 20:03

Use associations:

BarChart[
ChartLabels -> Automatic
]
`
• Szabolcs: Very nice idea to use the sort by association; I appreciate your approach too and it works well ... many thanks ... prg Commented May 3, 2017 at 20:35
• @PRG, please take a tour. To learn that you can express your gratitude with upvotes :)
– Kuba
Commented May 3, 2017 at 20:56