I have in total 16 datasets and want to make PieChart
s such that the colors are appropriate for the respective item. I tried with ColorFunction
but without result
Here a MWE to illustrate the problem with two datasets, pairs (item name, value):
data1 = {{"Label 1", 2}, {"Label 2", 4}, {"Label 3", 4}};
data2 = {{"Label 1", 2}, {"Label 2", 4}, {"Label 4", 4}};
so
allLabels = {"Label 1", "Label 2", "Label 3", "Label 4"};
colors = Hue /@ (Range[4]/4);
So we get the desired colorings:
and the colorChooser
:
colorChooser[label_String] :=
Select[labelColors, First[#] == label &][[1, 2]]
Then:
PieChart[data1[[All, 2]], ChartLegends -> data1[[All, 1]],
ColorFunction -> (colorChooser[#,1] &); (*Choose color for the item*)
ChartElementFunction -> "PlateauSector",
ChartLabels -> relativeData[[All, 2]]
]
delivers:
and
PieChart[data2[[All, 2]], ChartLegends -> data2[[All, 1]],
ColorFunction -> (colorChooser[#,1] &); (*Choose color for the item*)
ChartElementFunction -> "PlateauSector",
ChartLabels -> data2[[All, 2]]
]
The desired output would be that the items are colored according to the colortable, so "item 4" should be in red. How can I set up the ChartLegends
and the colorChooser
appropriate?