Statistics - Maple Programming Help

Home : Support : Online Help : Graphics : Statistics : Statistics/BarChart

Statistics

 BarChart
 create bar charts from data
 ColumnGraph
 create column graphs from data

 Calling Sequence BarChart(X, options, plotoptions) BarChart['interactive'](X) ColumnGraph(X, options, plotoptions) ColumnGraph['interactive'](X)

Parameters

 X - data options - (optional) equation(s) of the form option=value where option is one of datasetlabels, color, distance, format, offset, scale, or width; specify options for generating the bar chart plotoptions - options to be passed to the plots[display] command

Description

 • The BarChart command generates a bar chart for the specified data. Several formats are available for multiple data sets: default, stacked and percent stacked. See format option below for more information. The ColumnGraph command is similar to BarChart except that numerical values are represented by vertical columns.
 • The first parameter X is either a single data sample - given as e.g. a Vector - or a list of data samples. Note, that the individual samples may be of variable size. Alternatively, X can be specified as a list of equations of type value=frequency.
 • If the ['interactive'] option is used, then a dialog box appears that allows for customized creation of the plot.

Options

 The options argument can contain one or more of the options shown below. All unrecognized options will be passed to the plots[display] command. See plot[options] for details.
 • datasetlabels=none, relative, absolute, or list
 This option controls data set labels on the bars. The relative option will display, for each bar, the relative frequency of the corresponding value. The absolute option will display the absolute frequency of the corresponding value. Finally, one can specify data set labels as a list of strings or expressions.
 • color=name, list, or range
 This option specifies colors for the individual data sets. When a list of colors is given, each of the bars will be colored with the corresponding color in the list. If a range of colors is given, the colors will be generated by selecting an appropriate number of equally-spaced points in the corresponding hue range.
 • distance=nonnegative
 This option can be used to control the distance between the boxes. The default value is 0.2.
 • format=default or stacked
 By default, individual data sets are clustered together, so that the first cluster contains the first element from each data set, the second cluster contains the second element from each data set, etc. A stacked bar chart shows related data groups, one on top of the other. A percent bar chart is similar to a stacked bar chart, except that it is rescaled to a height of 1 while preserving proportionality. If scale is set to relative and format is set to stacked then a percent stacked plot will be generated.
 • offset=realcons
 Initial offset along the x-axis.
 • scale=absolute, or relative
 This option controls whether the absolute or relative data scale should be used. If scale is set to relative and format is set to default then all data samples will be rescaled so that their range belongs to an interval between -1 and 1. If scale is set to relative and format is set to stacked then a percent stacked plot will be generated.
 • width=realcons
 This option can be used to control the cluster width. The default value is 0.75.

Examples

 > $\mathrm{with}\left(\mathrm{Statistics}\right):$
 > $Z≔\mathrm{Sample}\left(\mathrm{Normal}\left(0,1\right),10\right):$
 > $A≔\mathrm{Array}\left(\left[\mathrm{seq}\left(2+\mathrm{sin}\left(\frac{10\mathrm{π}i}{15}+2{Z}_{i}\right),i=1..5\right)\right]\right):$
 > $B≔\mathrm{Array}\left(\left[\mathrm{seq}\left(2+\mathrm{sin}\left(\frac{10\mathrm{π}i}{15}+3{Z}_{i}\right),i=1..5\right)\right]\right):$
 > $C≔\mathrm{Array}\left(\left[\mathrm{seq}\left(2+\mathrm{sin}\left(\frac{10\mathrm{π}i}{15}+4{Z}_{i}\right),i=1..5\right)\right]\right):$
 > $\mathrm{ColumnGraph}\left(\left[A,B,C\right],\mathrm{title}="Column Graph",\mathrm{legend}=\left["A","B","C"\right]\right)$

Plot options such as background color or gridlines are passed to the plots:-display command:

 > $\mathrm{ColumnGraph}\left(\left[A,B,C\right],\mathrm{title}="Column Graph",\mathrm{legend}=\left["A","B","C"\right],\mathrm{background}="LightGrey",\mathrm{gridlines}\right)$
 > $T≔\left[\mathrm{StringTools}[\mathrm{CharacterFrequencies}]\left("antidisestablishmentarianism"\right)\right]:$
 > $\mathrm{BarChart}\left(T\right)$
 > $E≔\left[\mathrm{seq}\left(\mathrm{Array}\left(\mathrm{evalf}\left(\left[\mathrm{seq}\left(1+\mathrm{sin}\left(\frac{10\mathrm{π}i}{15j}\right),i=1..15\right)\right]\right)\right),j=1..15\right)\right]:$
 > $\mathrm{ColumnGraph}\left(E,\mathrm{format}=\mathrm{stacked},\mathrm{scale}=\mathrm{relative},\mathrm{color}="Firebrick".."Orange",\mathrm{gridlines}\right)$

The commands to create the plots from the Plotting Guide using the data above are

 > $\mathrm{BarChart}\left(\left[A,B,C\right]\right)$
 > $\mathrm{ColumnGraph}\left(E,\mathrm{format}=\mathrm{stacked},\mathrm{color}="Maroon".."RoyalBlue",\mathrm{gridlines}\right)$

The BarChart and ColumnGraph commands also accepts a Matrix. The columns are understood as individual data samples.

 > $M≔{\mathrm{Matrix}\left(\left[A,B,C\right],\mathrm{scan}=\mathrm{columns}\right)}^{\mathrm{%T}}$
 ${M}{≔}\left[\begin{array}{ccc}{1.94956824920307}& {1.09864970457959}& {1.18874740477055}\\ {1.62069799759165}& {1.94007198890158}& {2.26587736436439}\\ {1.05612104297007}& {1.03907718002638}& {1.37648949467898}\\ {2.57962144102022}& {2.39291308411754}& {2.18820146842307}\\ {1.16051145054777}& {1.17459841885234}& {1.18921905455788}\end{array}\right]$ (1)
 > $\mathrm{BarChart}\left(M\right)$
 > $\mathrm{ColumnGraph}\left(M\right)$

Additional options such as style and size are passed to the plots[display] command.

 > $X≔\mathrm{Sample}\left(\mathrm{Uniform}\left(0,1\right),100\right):$
 > $\mathrm{ColumnGraph}\left(X,\mathrm{distance}=0,\mathrm{style}=\mathrm{polygon},\mathrm{size}=\left[640,"golden"\right]\right)$
 >