Boxplot (Multiple)

Produce multiple box plots.

Complete Code

Download file: MultiBoxPlot.pg

POD for Macro Files

PG problem file

Explanation

DOCUMENT();

loadMacros('PGstandard.pl', 'PGML.pl', 'StatisticalPlots.pl', 'PGcourse.pl');

Preamble

The StatisticalPlots.pl macro is included. This provides some convenience methods for creating Statistical plots.

$params = [
    {
        min    => 700,
        q1     => 1100,
        median => 1300,
        q3     => 1700,
        max    => 2150

    },
    {
        min    => 400,
        q1     => 850,
        median => 1150,
        q3     => 1350,
        max    => 2000
    },
    {
        min    => 600,
        q1     => 950,
        median => 1175,
        q3     => 1250,
        max    => 1600
    }
];

$statPlot = StatPlot(
    ymin         => -2,
    ymax         =>  8,
    ytick_delta  =>  2,
    yminor       =>  0,
    yvisible     =>  1,
    ytick_labels => { 6 => 'Fri.', 4 => 'Sat.', 2 => 'Sun.' },
    show_grid    =>  0,
    xmin         => -500,
    xmax         =>  3000,
    xtick_delta  => 500
);
@fill_colors = ('LightBlue', 'LightGreen', 'Magenta');
@box_centers = (2,           4,            6);
for (0 .. $#box_centers) {
    $statPlot->add_boxplot(
        $params->[$_],
        orientation => 'horizontal',
        box_center  => $box_centers[$_],
        box_width   => 1,
        fill_color  => $fill_colors[$_],
        whisker_cap => 1
    );
}
$alt_text =
    'Three horizontal box plots. '
    . "The topmost one is labeled 'Fri.' with left most whisker $params->[0]{min} "
    . "the left side of the box is at $params->[0]{q1} and vertical line at "
    . "$params->[0]{median}, right side of the box at $params->[0]{q3} "
    . "and rightmost whisker at $params->[0]{max}."
    . "The box plot in the middle is labelled 'Sat.' with left most whisker "
    . "$params->[1]{min} the left side of the box is at $params->[1]{q1} and "
    . "vertical line at $params->[1]{median}, right side of the box at "
    . " $params->[1]{q3} and rightmost whisker at $params->[1]{max}."
    . "The box plot toward the bottom is labelled 'Sun.' with left most whisker "
    . "$params->[2]{min} the left side of the box is at $params->[2]{q1} and "
    . "vertical line at $params->[2]{median}, right side of the box at "
    . " $params->[2]{q3} and rightmost whisker at $params->[2]{max}.";

Setup

To create a graph, start with a StatPlot. The min and max options in the two directions give the bounding box of the plot. The tick_delta for each direction gives the distance between tick marks and the minor option is the number of minor ticks between each tick.

The three box plots are created by defining the $params, an array reference of the needed parameters. For each set of parameters, the box plot is created with the add_boxplot. The remaining arguments are options to the box plot. Note that in this example, we have selected three different colors for the box plots and each is given a whisker cap. See StatisticalPlots.pl for other options to this method.

Make sure that an alternate text is added to all graphs for accessibility. Be detailed.

BEGIN_PGML

>>[! [$alt_text] !]{$statPlot}{400}<<

END_PGML

Statement

In this case, only the plot is shown. Generally here is where questions are asked. Also note that the alt test is provided to the plot.

BEGIN_PGML_SOLUTION
Place a detailed solution here.
END_PGML_SOLUTION

ENDDOCUMENT();

Solution

A solution should be provided here.