Box Plot

BoxPlots are used to show statistics about multiple groups of observations.

For each group of observations, the box limits represent the lower quartile (25-th percentile) and upper quartile (75-th percentile). The median is displayed as a line across the box. Whiskers are drawn from the upper quartile to the upper adjacent value, and from the lower quartile to the lower adjacent value.

Optional notches may be displayed to show a 95 percent confidence interval about the median, at

where IRQ is the interquartile range and n is the number of observations. Outside and far outside values may be displayed as symbols. Outside values are outside the inner fence. Far out values are outside the outer fence.

The BoxPlot has several child nodes. Any of these nodes can be disabled by setting their Paint attribute to false.

      The Bodies node has the main body of the box plot elements. Its fill attributes determine the drawing of (notched) rectangle (see Fill Area Attributes). Its line attributes determine the drawing of the median line. The width of the box is controlled by the MarkerSize attribute (see Attribute MarkerSize).

      The Whiskers node draws the lines to the upper and lower quartile. Its drawing is affected by the marker attributes.

      The FarMarkers node holds the far markers. Its drawing is affected by the marker attributes.

      The OutsideMarkers node holds the outside markers. Its drawing is affected by the marker attributes.

Example

In this example, the Fisher iris data set is read from a file and a Box plot is created from data. The data is in a file called FisherIris.csv in the same directory as this class.

The y-axis labels are taken from the column names.

The boxes are colored green, the markers are all filled circles. The outside markers are blue and the far outside markers would be red, if there were any.

(Download Code)

 

import com.imsl.chart.*;

import com.imsl.io.FlatFile;

import java.io.*;

import java.util.StringTokenizer;

 

public class SampleBoxPlot extends JFrameChart {

 

    public SampleBoxPlot() throws IOException, java.sql.SQLException {

        // Read the data

        InputStream is =

                SampleBoxPlot.class.getResourceAsStream("FisherIris.csv");

        DataReader reader = new DataReader(is);

        int nColumns = 5;

        int nObs = 150;

        String labels[] = new String[nColumns];

        for (int i = 0; i < nColumns; i++) {

            labels[i] = reader.getMetaData().getColumnName(i + 1);

        }

        double irisData[][] = new double[nColumns][nObs];

        for (int j = 0; reader.next(); j++) {

            for (int i = 0; i < nColumns; i++) {

                irisData[i][j] = reader.getDouble(i + 1);

            }

        }

 

        // Setup the chart

        Chart chart = getChart();

        AxisXY axis = new AxisXY(chart);

        BoxPlot boxPlot = new BoxPlot(axis, irisData);

        boxPlot.setBoxPlotType(BoxPlot.BOXPLOT_TYPE_HORIZONTAL);

        boxPlot.setLabels(labels);

        boxPlot.getBodies().setFillColor(java.awt.Color.green);

        boxPlot.setMarkerType(BoxPlot.MARKER_TYPE_FILLED_CIRCLE);

        boxPlot.getOutsideMarkers().setMarkerColor(java.awt.Color.blue);

        boxPlot.getFarMarkers().setMarkerColor(java.awt.Color.red);

        boxPlot.setNotch(true);

    }

 

    public static void main(String argv[])

            throws IOException, java.sql.SQLException {

        new SampleBoxPlot().setVisible(true);

    }

 

    /**

     *  Read the Fisher Iris data

     */

    static private class DataReader extends FlatFile {

 

        public DataReader(InputStream is) throws IOException {

            super(new BufferedReader(new InputStreamReader(is)));

            String line = readLine();

            StringTokenizer st = new StringTokenizer(line, ",");

            for (int j = 0; st.hasMoreTokens(); j++) {

                setColumnName(j + 1, st.nextToken().trim());

                setColumnClass(j, Double.class);

            }

        }

    }

}



Visual Numerics - Developers of IMSL and PV-WAVE
http://www.vni.com/
PHONE: 713.784.3131
FAX:713.781.9260