I am trying to visualise multiple data sets in one histogram. When using one or two datasets, the automatic transparency of the bars keeps everything relatively easy to see. When going to three or more datasets however, quickly the colours become confusing and unclear, in particular when there is much overlap.
data = {RandomVariate[NormalDistribution[2, 2], 200],
RandomVariate[NormalDistribution[6, 2], 200],
RandomVariate[NormalDistribution[4, 3], 200]};
Histogram[data, ChartStyle -> {Blue, Green, Red}]
Instead of the transparency and the overlay of the colours, one can disable the transparency. The result of this however is that smaller bars can get hidden behind larger ones. Is there a way to make sure that the smallest bar in a certain bin is always in front of the larger ones? I have looked but all I found is the "Stacked"
option of ChartLayout
which is not what I am looking for.
Answer
k = Histogram[Tooltip[#, False] & /@ data, ChartStyle -> {Blue, Green, Red}]
(k /. {_[_[{_[_[_[{_, RectangleBox[a___]}]], _]}, _], _]} :> Rectangle[a]) /.
{_[___, _[c : RGBColor[__]]], b : {Rectangle[__] ..}} :> Thread[{c, b}] /.
{{{}, s : {{RGBColor[__], Rectangle[__]} ..}, __}} :> s /.
{s : {RGBColor[__], Rectangle[__]} ..} .. :> s /.
s : {{RGBColor[__], Rectangle[__]} ..} :>
(SortBy[#, -#[[2, 2, 2]] &] & /@ GatherBy[s, #[[2, 1]] &])
Comments
Post a Comment