3
$\begingroup$

I am having some issue getting DistributionChart to show bin widths as expected, or perhaps it is in my interpretation of the plots.

I have four data sets, all of the same length, and plot them in the same graph:

DistributionChart[{
RandomVariate[NormalDistribution[0, 1], {1000}],     
RandomVariate[NormalDistribution[0, 1], {1000}], 
RandomVariate[NormalDistribution[1, 0.1], {1000}], 
RandomVariate[NormalDistribution[0, 1], {1000}]}, 
Method -> {"BoxWidth" -> "Scaled"}]

This results in a plot of the same type as below:

enter image description here

Since all the data sets are the same size - 1000 elements - I would expect that the area of each plot should be the same. However, the third plot is much too small for that to be the case.

Does anyone know how I can get them to be comparable? In that the area would be the same across all four.

Best,

Ben

$\endgroup$
3
$\begingroup$

The vertical height is determined by the range of the data. The method you chose sets the maximum width to be proportional to the square root of the data sizes. Since the data sizes are identical, the maximum widths are identical. The shape shows how the data is distributed across the range of the data. Compare your results with different size data sets

DistributionChart[{RandomVariate[NormalDistribution[0, 1], {10000}], 
  RandomVariate[NormalDistribution[0, 1], {1000}], 
  RandomVariate[NormalDistribution[1, 0.1], {400}], 
  RandomVariate[NormalDistribution[0, 1], {100}]}, 
 Method -> {"BoxWidth" -> "Scaled"}]

enter image description here

DistributionChart[{RandomVariate[NormalDistribution[0, 1], {10000}], 
  RandomVariate[NormalDistribution[0, 1], {1000}], 
  RandomVariate[NormalDistribution[1, 0.1], {400}], 
  RandomVariate[NormalDistribution[0, 1], {100}]}, 
 Method -> {"BoxWidth" -> "Fixed"}]

enter image description here

$\endgroup$
  • 1
    $\begingroup$ Thanks. Is there a way to achieve a normalised density though? By this I mean that all data sets would be the same area. Best, Ben $\endgroup$ – ben18785 Jul 6 '15 at 15:44
3
$\begingroup$
{d1, d2, d3, d4} = RandomVariate[NormalDistribution @@ #, {1000}] & /@ 
  {{0, 1}, {0, 1}, {1, .2}, {0, 1}};

Using PairedSmoothHistogram and Show in combination with Translate:

histograms = Quiet @ PairedSmoothHistogram[#, #, PlotStyle -> #2, 
     FillingStyle -> Lighter[#2], Filling -> Axis, Axes -> False, 
     Frame -> False, Spacings -> 0] & @@@ 
   Transpose[{{d1, d2, d3, d4}, ColorData[97]/@Range[4]}];

Show[Graphics@ MapIndexed[Translate[#[[1]], {3 #2[[1]], 0}] &, histograms], 
 Frame -> True, PlotRangePadding -> {{2, 2}, {1, 1}},
 FrameTicks -> {{Automatic, Automatic}, 
  {Thread[{Range[3, 12, 3], CharacterRange["A", "D"]}],  Automatic}}]

enter image description here

Using DistributionChart with a custom ChartElementFunction:

ClearAll[ceF]
ceF = Module[{col = Charting`ChartStyleInformation["Color"]}, 
    Translate[Quiet @ PairedSmoothHistogram[#2, #2, PlotStyle -> col, 
       FillingStyle -> Lighter[col], Filling -> Axis, Axes -> False, 
       Frame -> False, Spacings -> 0][[1]], {#3[[1]] (Mean@#[[1]]), 0}]] &;

ll = 4; δ = 4;
Show[DistributionChart[Thread[{d1, d2, d3, d4} -> δ], 
 ChartElementFunction -> ceF, ChartStyle -> 1], 
 Frame -> True, PlotRangePadding -> {{0, δ - 1}, {1, 1}},
 FrameTicks -> {{Automatic, Automatic},
  {Thread[{Range[δ, δ  ll, δ], CharacterRange["A", "D"]}], Automatic}}]

enter image description here

$\endgroup$

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.