TransWikia.com

Add data points to BoxWhiskerChart

Mathematica Asked by Chiara on February 14, 2021

I am working with BoxWhiskerChart to plot my data, but I can’t figure out how to add the data points to the plot. I have read the help function many times and looked around this site, but I haven’t found a solution yet.

Basically what I want to do is to have a graph like I obtained with Origin (see pic).

Box and Whisker plot obtained with Origin

Can anybody help?

2 Answers

You are looking for the option ChartElementFunction. Obviously, you will need to add more to this, but here is the data portion:

Clear[dataWhisker];
dataWhisker[{{xmin_, xmax_}, _}, data_, _] := 
 With[{x = (xmax + xmin)/2}, {Opacity[0.2], Point[{x, #} & /@ data]}]

BoxWhiskerChart[RandomVariate[NormalDistribution[], {5, 100}], 
  ChartElementFunction -> dataWhisker]

enter image description here

There are a couple of additions that are possible like setting the maker, etc., and if I get the time, I will add to this. In the meantime, this should be a good start.

Answered by rcollyer on February 14, 2021

ClearAll[cF]
cF[cedf_: "BoxWhisker", o : OptionsPattern[]] := 
 Dynamic@With[{col = Darker@Darker@CurrentValue["Color"]}, {EdgeForm[{col, Thick}], 
    ChartElementDataFunction[cedf, o][##], 
    ListPlot[Thread[{Mean[#[[1]]], #2}], PlotStyle -> col, PlotMarkers -> #3[[1]]][[1]]}] &

Examples:

SeedRandom[3]
dt = RandomVariate[NormalDistribution[], {5, 10}];
markers = Graphics`PlotMarkers[][[;; 5]];

BoxWhiskerChart[Thread[dt -> markers], {{"MeanMarker", 1}, {"MedianMarker", None}}, 
 ChartStyle -> 1, ChartElementFunction -> cF[]]

Mathematica graphics

BoxWhiskerChart[Thread[dt -> markers], {{"MeanMarker", 1}, {"MedianMarker", None}}, 
 ChartStyle -> 1, ChartBaseStyle -> FaceForm[], 
 ChartElementFunction -> cF[]]

Mathematica graphics

Answered by kglr on February 14, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP