Dataset's documentation shows how to leverage GroupBy operator at multiple levels
titanic = ExampleData[{"Dataset", "Titanic"}];
titanic[GroupBy[Key["sex"]], GroupBy[Key["class"]], ratio, "survived"]
Taking a step further, can generate summary graphics in one line:
titanic[GroupBy[Key["sex"]], GroupBy[Key["class"]],
Counts /*
KeySort /* (PieChart[#, SectorOrigin -> {Automatic, 1},
ChartLegends -> Automatic] &), "survived"]
KeySort insures uniform color assignment to True
and False
; without it, some charts will have inverted colors.
Since all charts share the same interpretation, the 6 ChartLegends are redundant.
Is there an option for a single legend to appear, outside the frame of the Dataset?
Wouldn't it be great if the various Chart functions returned associations like <|"chart"->Graphics[...], "legend"->Graphics[...] |>
that can be more easily processed.
Also, BarChart[#, ChartLegends->Automatic]
inside Dataset doesn't work, but adding manual values, eg ChartLegends->{"T","F"} works.
Histogram
,BarChart
,PieChart
etc operate on nested data in precisely the way you are doing it 'manually' here. And then doing things like choosing the same bins across each category would be totally automatic, as would ensuring there is only one legend, colors are consistent, etc... All of this is possible, and in fact even planned, it just takes time. $\endgroup$