Produce a donut plot.
DOCUMENT();
loadMacros("PGstandard.pl", 'PGML.pl', 'StatisticalPlots.pl', 'PGcourse.pl');
Preamble
This uses the add_piechart method in the StatisticalPlots.pl
macro with the option to make it a donut plot. A pie chart version of
this is available at Pie Chart.
@values = (1, 5, 8, 2, 4);
@animals = ('Anteater', 'Bobcat', 'Camel', 'Dingo', 'Elephant');
$stat_plot = StatPlot(xvisible => 0, yvisible => 0, show_grid => 0);
$stat_plot->add_piechart(
~~@values,
labels => ~~@animals,
radius => 3.25,
inner_radius => 2.5,
angle_offset => 30,
stroke_width => 1,
rounded_corners => 1
);
$total = 0;
$total += $_ for (@values);
$alt_text = 'A pie chart of animals. ';
for (0 .. 4) {
$alt_text .=
"The size of the $animals[$_] wedge is about "
. Round(100 * $values[$_] / $total, 1)
. '% of the total. ';
}
Setup
In this example, the size of each wedge in the donut plot is given as an array.
The StatPlot is created with the axes and grid turned off. The
add_piechart method takes the number values in the
@values array. The values must be passed in as an array
reference (which is why the ~~ is needed).
For the options, the labels also need to be passed in as
an array reference. The radius and
inner_radius gives the outer and inner radii of the donut.
The angle_offset shifts the angle (in degrees) of the
starting sector from the horizontal axis.
The default colors come from the rainbow palette, and
other options exist.
A detailed alternative text should accompany all plots/graphs.
BEGIN_PGML
>> Donut Plot of the number of animals at the local zoo <<
>>[! [$alt_text] !]{$stat_plot}{400}<<
END_PGML
Statement
In this case, only the plot is provided with the alt text.
BEGIN_PGML_SOLUTION Place a detailed solution here. END_PGML_SOLUTION ENDDOCUMENT();
Solution
A solution should be provided here.