3
$\begingroup$

Suppose we have the following list with a row of integer numbers

data = {0, 0, -1, 1, 1, 2, 9, -2, 2, 1, 1, 1, 0, 0, 9, 9, -1, 0, 9, 2}

Each integer corresponds to a classification number. Now I want to create the following custom diagram:

enter image description here

If for example, the data list contains 20 integers then the circle should be divided into 20 sectors of equal area. Then each sector should be colored according to the value of the integer. The color code is the following:

-1 ---> yellow

-2 ---> purple

0 ---> green

1 ---> blue

2 ---> red

9 ---> cyan

The sectors should start from 12 o'clock and follow and clockwise orientation. Ideally, an arrow should indicate the direction.

Any suggestions?

$\endgroup$
  • $\begingroup$ What do you get when you run DeleteDuplicates[data] for your actual data? $\endgroup$ – kglr Dec 12 '19 at 10:52
  • $\begingroup$ @kglr I get a second list but I do not want to remove any data. I beleive that the issue is due to the boundaries. How can we have white boudnaries in each sector? $\endgroup$ – Vaggelis_Z Dec 12 '19 at 10:55
4
$\begingroup$
coloring = Thread[{-1, -2, 0, 1, 2, 9} -> {Yellow, Purple, Green, Blue, Red, Cyan}]; 
data = {0, 0, -1, 1, 1, 2, 9, -2, 2, 1, 1, 1, 0, 0, 9, 9, -1, 0, 9, 2};
ca = ConstantArray[1, Length @ data];

PieChart[ca, 
 SectorOrigin -> {{Pi/2, "Clockwise"}, 0}, 
 ChartStyle -> (data /. coloring), 
 ChartLabels -> Placed[{data, Range[Length@data]}, {"RadialCenter", "RadialOutside"}],
 ChartBaseStyle -> EdgeForm[White]

enter image description here

Use "RadialCallout" instead of "RadialOutside" to get

enter image description here

Use SectorOrigin -> {{Pi/2, "Clockwise"}, 1} to get

enter image description here

Update: Remove labels and add an arrow and legend:

PieChart[ca, 
 SectorOrigin -> {{π/2, "Clockwise"}, 0}, 
 ChartStyle -> (data /. coloring), ChartBaseStyle -> EdgeForm[White], 
 Epilog -> {Line[{{0, 1}, {0, 1.2}}],
   Arrowheads[Medium], Arrow[1.1 {Cos@#, Sin@#} & /@ Subdivide[π/2, π/4, 10]]},
 ChartLegends -> (SwatchLegend[#2, #] & @@ Transpose[List @@@ coloring])]

enter image description here

Add label to one of the sectors:

PieChart[MapAt[Labeled[#, "this is\na test", "RadialCallout"] &, ca, {13}], 
 SectorOrigin -> {{π/2, "Clockwise"}, 0}, 
 ChartStyle -> (data /. coloring), ChartBaseStyle -> EdgeForm[White], 
 Epilog -> {Line[{{0, 1}, {0, 1.2}}], Arrowheads[Medium], 
   Arrow[1.1 {Cos@#, Sin@#} & /@ Subdivide[π/2, π/4, 10]]}, 
 ChartLegends -> (SwatchLegend[#2, #] & @@ 
    Transpose[List @@@ coloring])]

enter image description here

positions = {5, 13, 17};
labels = {"label5", "label13", "label17"};

ca[[positions]] = MapThread[Labeled[#, #2, "RadialCallout"] &, 
  {ca[[positions]], labels}];

PieChart[ca, SectorOrigin -> {{π/2, "Clockwise"}, 0}, 
 ChartStyle -> (data /. coloring), ChartBaseStyle -> EdgeForm[White], 
 Epilog -> {Line[{{0, 1}, {0, 1.2}}], Arrowheads[Medium], 
   Arrow[1.1 {Cos@#, Sin@#} & /@ Subdivide[π/2, π/4, 10]]}, 
 ChartLegends -> (SwatchLegend[#2, #] & @@ Transpose[List @@@ coloring])]

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ Please, see my edit. $\endgroup$ – Vaggelis_Z Dec 12 '19 at 10:45
  • $\begingroup$ I suspect that the problem is the fact that there are black solid lines at the boundaries of each sector. Is there a way to have white boundaries? $\endgroup$ – Vaggelis_Z Dec 12 '19 at 10:49
  • $\begingroup$ @Vaggelis_Z, try adding the option ChartBaseStyle -> EdgeForm[White]. $\endgroup$ – kglr Dec 12 '19 at 10:56
  • $\begingroup$ That fixed the issue with the dark colors! Now is there a way to mark the origin with a vertical line (as in my initial plot) and also add an arrow indicating the direction of sectors? $\endgroup$ – Vaggelis_Z Dec 12 '19 at 11:00
  • $\begingroup$ @Vaggelis_Z, please see the update. $\endgroup$ – kglr Dec 12 '19 at 11:14

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.