Group Abstract Group Abstract

Message Boards Message Boards

How do I merge a boxplot with distribution plot?

Posted 2 years ago

Hi,

How do I merge the distribution plot to the box plot in Mathematica like the below figure?

Jan = {2.09, 0.9, 317.4, 472.400, 417.79, 234.200, 325., 524.2, 49.59,
    114.7, 126.1, 136., 160.6, 203.2, 157.8, 0., 8., 23.5};

Feb = {0., 0., 0.5, 111.2, 155.700, 324.59, 152.5, 348.3, 222., 0., 
   0., 0., 0., 0., 24., 186., 118.3, 387.3};

BoxWhiskerChart[{Jan, Feb}, FrameLabel -> {"Month", "Discharge"}, 
 ChartLabels -> {{"\!\(\*
StyleBox[\"Jan\",\nFontSize->16]\)", "\!\(\*
StyleBox[\"Feb\",\nFontSize->16]\)"}}]

enter image description here

POSTED BY: Alex Teymouri
4 Replies
Posted 2 years ago
Posted 2 years ago

Here's a very ad hoc approach:

Jan = {2.09, 0.9, 317.4, 472.400, 417.79, 234.200, 325., 524.2, 49.59,
    114.7, 126.1, 136., 160.6, 203.2, 157.8, 0., 8., 23.5};

Feb = {0., 0., 0.5, 111.2, 155.700, 324.59, 152.5, 348.3, 222., 0., 
   0., 0., 0., 0., 24., 186., 118.3, 387.3};

Show[
 ListPlot[{{0.5, -250}, {4.5, 800}}, PlotRange -> {{0.5, 4.5}, {-250, 800}}, Frame -> True,
  FrameTicks -> {{Automatic, Automatic}, {{{1.5, "Jan"}, {3.5, "Feb"}}, None}}, PlotStyle -> White, Frame -> True],
 BoxWhiskerChart[{{}, Jan, {}, Feb}],
 DistributionChart[{Jan, {}, Feb, {}}, ChartElementFunction -> "SmoothDensity"],
 DistributionChart[{Jan, {}, Feb, {}}, ChartElementFunction -> "PointDensity", 
  ChartStyle -> Directive[{GrayLevel[10, 10], Opacity[0.3], EdgeForm[]}]]
 ]

Density and box plots

But your data is problematic for the available density plot in DistributionChart because those distributions are (likely) bounded by zero. Getting an appropriate density function for such cases would require the "Bounded" option in SmoothKernelDistribution.

POSTED BY: Jim Baldwin
Posted 2 years ago

Thank you so much, Jim. I appreciate your time.

POSTED BY: Alex Teymouri

You may try with Epilog and Inset.

POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard