2
$\begingroup$

This is probably easy to solve, but I can't figure out how. I have a SectorChartlike this:

size1 = 10; size2 = 3;
secDat = Table[{1, 1}, {x, 1, size2}, {y, 1, size1}];
graph = SectorChart[secDat, ChartLayout -> "Grouped", 
  PerformanceGoal -> "Speed", SectorOrigin -> {Automatic, 20}, 
  SectorSpacing -> {0, 0}, 
  ChartLabels -> 
   Placed[Table["Label" <> ToString@x, {x, 1, size1}], "RadialInside",
     Rotate[#, 90 Degree] &], 
  ChartLegends -> 
   Placed[Table["Legend" <> ToString@x, {x, 1, size2}], Below]]

How can I:

  1. Place only one label on the inside of each sector? The labels are shown here three times, one label for each sector somehow, i.e. three times the same label.

  2. Rotate the labels such that each label is perpendicular to its own sectors? I tried to rotate the labels, but then only label 3 and 8 become perpendicular.

Any help appreciated!

$\endgroup$
4
$\begingroup$

Update 2: Changing the orientation of labels based on sector positions:

ClearAll[cedF2]
cedF2[datafunc_: ChartElementDataFunction["Sector"]][{{t0_, t1_},
  {r0_, r1_}}, y_, z___] := Module[{pos = If[-Pi/2 < (t0 + t1)/2 < Pi/2, Right, Left], 
   shift = If[-Pi/2 < (t0 + t1)/2 < Pi/2, Pi, 0]},
  {datafunc[{{t0, t1}, {r0, r1}}, y, {}], 
   If[z === {}, {}, {Darker[Darker[Charting`ChartStyleInformation["Color"]]], 
      Text[z[[1]], (r0 - .1) {Cos[(t0 + t1)/2], Sin[(t0 + t1)/2]}, {pos, Center}, 
     - (r0 - .0001) {Cos[(t0 + t1)/2 + shift], Sin[(t0 + t1)/2 + shift]}]}]}]

SectorChart[secDat3, ChartLayout -> "Grouped", 
 PerformanceGoal -> "Speed", SectorOrigin -> {Automatic, 20}, 
 SectorSpacing -> {0, 0}, ImageSize -> 500, 
 BaseStyle -> {FontSize -> Scaled[.04]}, ChartElementFunction -> cedF2[]]

enter image description here

Update: A custom ChartElementFunction to rotate the labels based on sector position:

ClearAll[cedF]
cedF[datafunc_: ChartElementDataFunction["Sector"]][{{t0_, t1_}, {r0_,
      r1_}}, y_, z___] := {datafunc[{{t0, t1}, {r0, r1}}, y, {}], 
   Darker[Darker[Charting`ChartStyleInformation["Color"]]], 
   Text[z[[1]], (r0 - .1) {Cos[(t0 + t1)/2], 
      Sin[(t0 + t1)/2]}, {Left, 
     Center}, - (r0 - .0001) {Cos[(t0 + t1)/2], Sin[(t0 + t1)/2]}]};
cedF[datafunc_: ChartElementDataFunction["Sector"]][{{t0_, t1_}, {r0_,
     r1_}}, y_, {}] := datafunc[{{t0, t1}, {r0, r1}}, y, {}]

As before, attach labels to the first dataset as metadata to be processed by cedF:

secDat3 = secDat;
labels3 = Table["Label" <> ToString@x, {x, 1, size1}];
secDat3[[1]] = Thread[secDat3[[1]] -> labels3];

SectorChart[secDat3, ChartLayout -> "Grouped", 
 PerformanceGoal -> "Speed", SectorOrigin -> {Automatic, 20}, 
 SectorSpacing -> {0, 0}, ImageSize -> 500, 
 BaseStyle -> {FontSize -> Scaled[.04]}, 
 ChartElementFunction -> cedF[]]

enter image description here

SectorChart[secDat3, ChartLayout -> "Grouped", 
 PerformanceGoal -> "Speed", SectorOrigin -> {Automatic, 10}, 
 SectorSpacing -> {0, 0}, ImageSize -> 500, 
 BaseStyle -> {FontSize -> Scaled[.04]}, 
 ChartElementFunction -> cedF[ChartElementDataFunction["OscillatingSector", 
    "AngularFrequency" -> 20, "RadialAmplitude" -> 0.25]]]

enter image description here

Original answer:

For part (1) the question, a work-around: Wrap only the first data set with Labeled. For part (2) TODO: modify this answer

secDat2 = secDat;
labels = Table[{Rotate[#, 90 Degree] &@("Label" <> ToString@x), "RadialInside"}, 
   {x, 1, size1}];
secDat2[[1]] = Labeled[#, ## & @@ #2] & @@@ Transpose[{secDat2[[1]], labels}];

SectorChart[secDat2, ChartLayout -> "Grouped", 
 PerformanceGoal -> "Speed", SectorOrigin -> {Automatic, 20}, 
 SectorSpacing -> {0, 0}, 
 ChartLegends -> Placed[Table["Legend" <> ToString@x, {x, 1, size2}], Below]]

enter image description here

$\endgroup$
  • $\begingroup$ Thanks kglr!! That works well for the first part, but I meant that the labels should be perpendicular to their own sectors, e.g. label 4 needs another rotation of around 45 to the right to be perpendicular to its sectors asf. $\endgroup$ – holistic Jul 31 '17 at 20:39
  • $\begingroup$ @holistic, the linked answer has a method for rotating of labels based on the sector angles. I will see if I can adapt it to the current case. $\endgroup$ – kglr Jul 31 '17 at 20:45
  • $\begingroup$ @holistic, updated. $\endgroup$ – kglr Jul 31 '17 at 22:13
  • $\begingroup$ Brilliant solution - May I suggest one improvement? For better readability the interior labels should be flipped at clock one $\endgroup$ – eldo Jul 31 '17 at 22:41
  • $\begingroup$ Thank you @eldo. Great point. I'll see if I can get that in. $\endgroup$ – kglr Jul 31 '17 at 22:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.