3
$\begingroup$
  1. Using ChartLayout, the histograms are tiled as expected as below, however the ChartStyle is not reflected (histograms with different colors was expected). What should I fix?
a = {1, 2, 2, 2, 1}; b = {1, 1, 1, 2};

Histogram[
  {a, b}, ChartLayout -> "Column", 
  ChartStyle -> {Opacity[.25, Red], Opacity[.25, Blue]}
]

enter image description here

  1. Could rectangles in the two histograms be located side by side as shown in the example below? (I've searched docs but I couldn't find.)

enter image description here

$\endgroup$

2 Answers 2

2
$\begingroup$
bins = HistogramList[Join[a, b]][[1]];

heights = HistogramList[#, {bins}][[2]] & /@ {a, b};

BarChart[heights, 
 ChartLabels -> MovingAverage[bins, 2], 
 ChartStyle -> {Opacity[.25, Red], Opacity[.25, Blue]}, 
 BarSpacing -> {0, .5}, Frame -> True]

enter image description here

$\endgroup$
3
$\begingroup$
styles = {Opacity[.25, Red], Opacity[.25, Blue]};

postProcess := ReplaceAll[r_Rectangle :> {Last[styles = RotateLeft[styles]], r}];


postProcess @ Histogram[{a, b}, ChartLayout -> "Column"]

enter image description here

postProcess @ Histogram[{a, b}, ChartLayout -> "Row"]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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