import java.util.*;

 

import org.jfree.chart.*;

 

import statgraphics.*;

import static statgraphics.util.Argument.*;

import static statgraphics.util.PlotType.*;

import statgraphics.util.*;

 

/**

 *

 * <p>Example: class StatisticalPlots.</p>

 */

 

public class StatisticalPlotsExample

{

 

    public static void main(String[] args)

    {

        String[] category = {"Apple", "Compaq", "GateWay 2000", "IBM",

                         "Packard Bell"};

        double[][] data = { {13, 12, 5, 9, 11}, {12, 13, 6, 8, 11},

                        {14, 11, 4, 11, 10} };

        String[] dataNames = {"2002", "2003", "2004"};

        PlotFrame[] pf = new PlotFrame[12];

        Hashtable argument = new Hashtable();

        argument.put(PLOT_TYPE, BAR);

        argument.put(TITLE, "Bar Plot B");

        argument.put(XLABEL, "Company");

        argument.put(YLABEL, "Frequency");

        argument.put(DATA_NAMES, dataNames);

        argument.put(PLOT_OPTION, "3D");

        GraphicalAnalysis graphicalAnalysis = new StatisticalPlots(argument,

                category, data).graphicalAnalysis;

        JFreeChart plot =

(JFreeChart) graphicalAnalysis.output.get("PLOT");

        pf[0] = new PlotFrame("3D Bar Plot", plot, 500, 270);

 

        argument.clear();

        argument.put(PLOT_TYPE, BAR);

        argument.put(DATA_NAMES, dataNames);

        argument.put(PLOT_OPTION, "2D");

        graphicalAnalysis = new StatisticalPlots(argument, category, data).

                            graphicalAnalysis;

        plot = (JFreeChart) graphicalAnalysis.output.get("PLOT");

        pf[1] = new PlotFrame("2D Bar Plot ", plot, 500, 270);

 

        category = new String[]

{"Apple", "Compaq", "GateWay 2000", "IBM", "Packard Bell"};

        data[0] = new double[] {13, 12, 5, 9, 11};

        argument.clear();

        argument.put(PLOT_TYPE, PIE);

        graphicalAnalysis = new StatisticalPlots(argument, category, data[0]).

                            graphicalAnalysis;

        plot = graphicalAnalysis.plot;

        pf[2] = new PlotFrame("2D Pie Plot", plot, 500, 270);

 

        argument.clear();

        argument.put(PLOT_TYPE, PIE);

        argument.put(PLOT_OPTION, "3D");

        graphicalAnalysis = new StatisticalPlots(argument, category, data[0]).

                            graphicalAnalysis;

        plot = graphicalAnalysis.plot;

        pf[3] = new PlotFrame("3D Pie Plot", plot, 500, 270);

 

        data = new double[][] { {12, 14, 19, 18, 15, 15, 18, 17, 20, 27, 22, 23,

               22, 21, 33, 28, 14, 18, 16, 13}, {4, 2, 3, 2, 6, 9, 2, 5, 6, 6,

               12, 2, 11, 9, 6, 9, 8, 9, 2, 7} };

        dataNames = new String[] {"2004", "2005"};

        argument.clear();

 

        argument.put(PLOT_TYPE, HISTOGRAM);

        argument.put(DATA_NAMES, dataNames);

        argument.put(BIN_NUMBER, 5);

        graphicalAnalysis = new StatisticalPlots(argument, data).

                            graphicalAnalysis;

        plot = (JFreeChart) graphicalAnalysis.output.get("PLOT");

        pf[4] = new PlotFrame("Histogram", plot, 500, 270);

 

        int[][][] time = new int[2][12][6];

        data = new double[2][12];

        dataNames = new String[] {"Company A", "Company B"};

        for (int j = 0; j < 2; j++)

        {

            for (int i = 0; i < 12; i++)

            {

                time[j][i][0] = 0;

                time[j][i][1] = 0;

                time[j][i][2] = 0;

                time[j][i][3] = 1;

                time[j][i][4] = i + 1;

                time[j][i][5] = 2005;

                data[j][i] = 100 + Math.random() * 20.0;

            }

        }

        argument.clear();

        argument.put(PLOT_TYPE, TIME_SERIES);

        argument.put(DATA_NAMES, dataNames);

        argument.put(TITLE, "Time Series Plot");

        argument.put(XLABEL, "Date");

        argument.put(YLABEL, "Stock Price");

        graphicalAnalysis = new StatisticalPlots(argument, time, data).

                            graphicalAnalysis;

        plot = graphicalAnalysis.plot;

        pf[5] = new PlotFrame("Time Series Plot", plot, 500, 270);

 

        data = new double[12][20];

        for (int i = 0; i < 12; i++)

        {

            for (int j = 0; j < 20; j++)

            {

                data[i][j] = -10 + Math.random() * 20.0;

            }

        }

        dataNames = new String[]

 {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"};

        argument.clear();

        argument.put(PLOT_TYPE, BOX);

        argument.put(DATA_NAMES, dataNames);

        argument.put(TITLE, "Box Plot");

        argument.put(XLABEL, "Category");

        argument.put(YLABEL, "Data Value");

        graphicalAnalysis = new StatisticalPlots(argument, data).

                            graphicalAnalysis;

        plot = graphicalAnalysis.plot;

        pf[6] = new PlotFrame("Box Plot", plot, 500, 270);

 

        Date[] date = new Date[12];

        for (int i = 0; i < 12; i++)

        {

            date[i] = new Date(105, i - 1, 21);

        }

        argument.remove(DATA_NAMES);

        graphicalAnalysis = new StatisticalPlots(argument, date, data).

                            graphicalAnalysis;

        plot = graphicalAnalysis.plot;

        pf[7] = new PlotFrame("Box Plot", plot, 500, 270);

 

        double xdata[][] = { {2, 5, 1, 3, 4, 1, 5, 3, 4, 2},

                         {2, 3, 4, 2, 5, 3, 4, 1, 3, 4} };

        double[][] ydata = { {50, 57, 41, 54, 54, 38, 63, 48, 59, 46},

                         {39, 42, 37, 32, 42, 45, 32, 43, 45, 35} };

        dataNames = new String[] {"2004", "2005"};

        argument.clear();

        argument.put(PLOT_TYPE, SCATTER);

        argument.put(DATA_NAMES, dataNames);

        graphicalAnalysis = new StatisticalPlots(argument, xdata, ydata).

                            graphicalAnalysis;

        plot = graphicalAnalysis.plot;

        pf[8] = new PlotFrame("Scatter Diagram", plot, 500, 270);

 

        double[][] sortXData = { {9, 14, 19, 24, 29, 34},

                             {11, 13, 17, 22, 26, 28, 31} };

        double[][] sortYData = { {0, 4, 12, 17, 19, 20},

                             {0, 2, 10, 13, 15, 16, 18} };

        dataNames = new String[] {"Company A", "Company B"};

        argument.clear();

        argument.put(PLOT_TYPE, LINE);

        argument.put(DATA_NAMES, dataNames);

        argument.put(TITLE, "Ogive Plot");

        argument.put(XLABEL, "Audit Time in Days");

        argument.put(YLABEL, "Cumulative Frequency");

        graphicalAnalysis =

new StatisticalPlots(argument, sortXData, sortYData).

graphicalAnalysis;

        plot = graphicalAnalysis.plot;

        pf[9] = new PlotFrame("Exploratory Data Analysis", plot, 500, 270);

 

        double[] variance = {3.59, 1.63, 1.11, 0.70, 0.38, 0.30, 0.14, 0.11};

        String[] componentList = {

"Comp. 1", "Comp. 2", "Comp. 3", "Comp. 4",

           "Comp. 5", "Comp. 6", "Comp. 7", "Comp. 8"};

        dataNames[0] = "Component";

        argument.put(DATA_NAMES, dataNames[0]);

        argument.put(TITLE, "Principal Component Analysis");

        argument.put(XLABEL, "Principal Component");

        argument.put(YLABEL, "Variance");

        graphicalAnalysis =

new StatisticalPlots(argument, componentList, variance).

graphicalAnalysis;

        plot = graphicalAnalysis.plot;

        pf[10] = new PlotFrame("Scree Plot", plot, 500, 270);

 

        double[][] xData = new double[2][2000];

        double[][] yData = new double[2][2000];

        dataNames = new String[] {"Power function", "Sine Function"};

        for (int j = 0; j < 2; j++)

        {

            if (j == 0)

            {

                for (int i = 0; i < 2000; i++)

                {

                    xData[j][i] = -10 + 0.01 * i;

                    yData[j][i] = Math.pow(xData[j][i], 2.0);

                }

            }

            else

            {

                for (int i = 0; i < 2000; i++)

                {

                    xData[j][i] = -20 + 0.02 * i;

                    yData[j][i] = 100 * Math.sin(xData[j][i]);

                }

            }

        }

        argument.put(DATA_NAMES, dataNames);

        argument.put(TITLE, "Mathematical Functions");

        argument.put(XLABEL, "x");

        argument.put(YLABEL, "f(x)");

        graphicalAnalysis = new StatisticalPlots(argument, xData, yData).

                            graphicalAnalysis;

        plot = graphicalAnalysis.plot;

        pf[11] = new PlotFrame("Mathematical Functions", plot, 500, 270);

 

        new PlotFrameFactory().putPlotFrame(pf);

    }

 

}

 

Results: