Mathematical Principles for Scientific Computing and Visualization
http : // www.farinhansford.com/books/scv
by Gerald Farin and Dianne Hansford

This notebook demonstrates the box and whiskers plot or boxplot. Suppose we are given k data values m_1, ...m_k. This is a tool to visualize these data with five numbers:
-- the median
-- the upper and lower quartile 
-- the upper and lower whiskers (smallest and largest non-outlier observation)
These elements are described in the notebook below.

Points outside of the whiskers are considered to be outliers. The whiskers are formed by offsetting the upper and lower quartile by a fraction of their difference.

Figures 12.17 and 12.14 were created with this notebook.

See Chapter 12 : Visualization of Empirical Data for details.

Updated May 2008

Needs["StatisticalPlots`" ]

(* set folder for output *)
(SetDirectory[ToFileName[Extract["FileName"/.NotebookInformation[EvaluationNotebook[]],{1},FrontEnd`FileName]]];) 

(* ---------------- dense data set -------------  *)

(datadense={0.4`,0.41`,0.43`,0.44`,0.48`,0.49`,0.5`,0.55`,0.51`,0.52`,0.525`,0.53`,0.6`,0.63`,0.64`,0.65`,0.66`,0.68`,0.7`,0.71`,0.72`,0.73`};) 

Print["Number of points in first (rather uniformly dense) data set = ",Length[datadense] ]

(* bring the data set into a form for plotting *)
(joindatadense=Table[{0,datadense[[k]]},{k,1,Length[datadense]}];) 

(* Create a plot of the data values *)
(g1dense=ListPlot[joindatadense,PlotStyle->PointSize[0.02],PlotRange->All,Axes->{False,True},PlotRange->All,BaseStyle->{"FontFamily"->"Helvetica","FontSize"->11},DisplayFunction->Identity,ColorOutput->GrayLevel];) 

(* Create the corresponding box and whiskers plot *)
(g2dense=BoxWhiskerPlot[datadense,BoxOutliers->All,BoxFillingStyle->GrayLevel[0.7],BaseStyle->{"FontFamily"->"Helvetica","FontSize"->11},DisplayFunction->Identity,ColorOutput->GrayLevel];) 

(* Put the plots together *)
(gdense=GraphicsRow[{g1dense,g2dense}];) 

(* Now display it *)
Show[gdense,DisplayFunction->$DisplayFunction] 


(* ---------------- biased data set -------------  *)

(databiased={0.4`,0.405`,0.41`,0.415`,0.42`,0.425`,0.43`,0.435`,0.44`,0.45`,0.46`,0.47`,0.48`,0.485`,0.49`,0.5`,0.51`,0.6`,0.61`,0.62`,0.63`,0.7`};) 

Print["Number of points in second (biased) data set = ",Length[databiased] ]
Print["Demonstrates an outlier"]

(joindatabiased=Table[{0,databiased[[k]]},{k,1,Length[databiased]}];) 

(g1biased=ListPlot[joindatabiased,PlotStyle->PointSize[0.02],PlotRange->All,Axes->{False,True},PlotRange->All,BaseStyle->{"FontFamily"->"Helvetica","FontSize"->11},DisplayFunction->Identity,ColorOutput->GrayLevel];) 

(g2biased=BoxWhiskerPlot[databiased,BoxOutliers->All,BoxFillingStyle->GrayLevel[0.7],BaseStyle->{"FontFamily"->"Helvetica","FontSize"->11},DisplayFunction->Identity,ColorOutput->GrayLevel];) 

(gbiased=GraphicsRow[{g1biased,g2biased}];) 

Show[gbiased,DisplayFunction->$DisplayFunction] 

(* gall=(⁃GraphicsArray⁃); *) 

(* ----- show three experiments ---- *)

datam = RandomReal[1,{20,3}];

Print["Three data sets with 20 values from a random number generator"]

 exper = BoxWhiskerPlot[datam, BoxFillingStyle->GrayLevel[0.7],BoxLabels->{"data set 1", "data set 2", "data set 3"}, BaseStyle->{"FontFamily"->"Helvetica","FontSize"->11},DisplayFunction->Identity,ColorOutput->GrayLevel];

Show[exper,DisplayFunction->$DisplayFunction] 




(* ---------------- output to files -------------  *)

(Export["bwplot_biasdata.eps",g1biased];) (Export["bwplot_bias.eps",g2biased];) (Export["bwplot_densedata.eps",g1dense];) (Export["bwplot_dense.eps",g2dense];)
(Export["bwplot_exper.eps",exper];)