 BarChart - Maple Help

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, colorscheme, offset, distance, width, format or scale; 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 displays, for each bar, the relative frequency of the corresponding value. The absolute option displays the absolute frequency of the corresponding value. Finally, you can specify data set labels as a list of strings or expressions.
 • color=name, list, range, Matrix or DataFrame
 When specified as a list or a range of colors, the option is used for coloring individual data sets. For a list of colors, each of the bars is colored with the corresponding color in the list. If a range of colors is given, a list is generated by selecting an appropriate number of equally spaced points in the corresponding hue range.
 If both color and X are specified as Matrices, then each of the values in X gets mapped to the color located in the corresponding cell of the color Matrix and the bars are then colored accordingly. For DataFrames this mapping is done while taking the appropriate labels into account.
 In the case where X consists of a list of data samples, each data sample gets mapped to the corresponding column of the color Matrix or DataFrame.
 • colorscheme=[ "valuesplit", V', mapping ]
 The first parameter in colorscheme specifies the arguments to the plotting command and for BarChart must always be set to "valuesplit" when colorscheme is defined.
 V is an optional rtable or a list of $n$ elements, where $n$ is the total number of expected bars in the plot structure.
 The $i$th entry in V corresponds to the $i$th entry in the data sample.
 If X is specified as a list of data samples and V is given as a Matrix then each data sample corresponds to a column in V.
 When both X and V are specified as Matrices, each of the values in X gets mapped to the value located in the corresponding cell of V. For DataFrames the appropriate labels are taken into account.
 If V is not provided, X itself is used instead in place of V.
 The mapping argument is commonly defined as a list of equalities specifying the mapping of values in V to colors. In the event where the mapping parameter is not supplied, a suitable color mapping for each of the distinct elements of V is automatically created with colors chosen from a default color palette. (See the plot/color help page for information about default colors for plotting.)
 For details about the colorscheme/valuesplit option see valuesplit(colorscheme).
 • offset=realcons
 Initial offset along the x-axis. The default value is 0.
 Note: By default, the view wraps tightly around all visible plot objects and the horizontal axis is marked by data set labels, not regular coordinates, so this option will have no (visual) effect. It is meant for the case where this plot is combined with other plot elements.
 • distance=nonnegative
 This option controls the distance between the boxes. The default value is 0.25.
 • width=realcons
 This option controls the cluster width. The default value is 0.75.
 The following plot illustrates how the options offset, distance, and width are interpreted – Note the lengths of the arrows labeled "offset", "width", and "distance" correspond to values for the offset, width, and distance options respectively.
 • 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 is generated.
 • scale=absolute or relative
 This option controls whether the absolute or relative data scale is used. If scale is set to relative and format is set to default then all data samples are 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 is generated. Notes

 • Note that the labels for the data sets are placed on the axes, and should not be confused for coordinates.
 • In the event where the options colorscheme and color are both specified, the colorscheme option takes precedence over the color option. 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{Pi}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{Pi}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{Pi}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{Pi}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 accept 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}{2.12894506664340}& {1.67629649114914}& {1.29064171080231}\\ {1.05449890294367}& {2.72531894026057}& {1.62549295488853}\\ {2.25713708429253}& {1.07512430481843}& {1.50301833174961}\\ {2.55164396083256}& {1.83013109809510}& {1.20094178420900}\\ {1.95836412566877}& {2.44495759054641}& {2.82142304303481}\end{array}\right]$ (1)
 > $\mathrm{BarChart}\left(M\right)$ > $\mathrm{ColumnGraph}\left(M,\mathrm{color}="Orange".."Red"\right)$ Using Data Frames to specify the color option

 > $\mathrm{dataDF}≔\mathrm{DataFrame}\left(⟨⟨6|3|9⟩,⟨3|5|9⟩⟩,'\mathrm{rows}'=\left['\mathrm{r1}','\mathrm{r2}'\right],'\mathrm{columns}'=\left['\mathrm{c1}','\mathrm{c2}','\mathrm{c3}'\right]\right):$
 > $\mathrm{colorDF}≔\mathrm{DataFrame}\left(⟨⟨\mathrm{pink}|\mathrm{green}|\mathrm{black}⟩,⟨\mathrm{yellow}|\mathrm{red}|\mathrm{blue}⟩⟩,'\mathrm{rows}'=\left['\mathrm{r2}','\mathrm{r1}'\right],'\mathrm{columns}'=\left['\mathrm{c3}','\mathrm{c1}','\mathrm{c2}'\right]\right):$
 > $\mathrm{ColumnGraph}\left(\mathrm{dataDF},\mathrm{color}=\mathrm{colorDF}\right)$ The colorscheme option can also be used to color bars by their values

 > $\mathrm{Statistics}:-\mathrm{ColumnGraph}\left(\mathrm{LinearAlgebra}:-\mathrm{RandomVector}\left(50\right),\mathrm{colorscheme}=\left["valuesplit",\left[-\mathrm{∞}..-51="Blue",-50..50="DarkGreen",51..\mathrm{∞}="DarkRed"\right]\right]\right)$ > $\mathrm{dataM}≔\mathrm{Matrix}\left(⟨⟨\mathrm{Statistics}:-\mathrm{Sample}\left(\mathrm{Uniform}\left(0,1\right),\left[20,2\right]\right)⟩|\mathrm{LinearAlgebra}:-\mathrm{RandomVector}\left(20,\mathrm{generator}=\mathrm{rand}\left(0..3\right)\right)⟩\right):$
 > $\mathrm{Statistics}:-\mathrm{BarChart}\left({\mathrm{dataM}}_{\left(\right)..\left(\right),1},\mathrm{colorscheme}=\left["valuesplit",{\mathrm{dataM}}_{\left(\right)..\left(\right),3},\left[0="Red",1="Blue",2="Green",3="Purple"\right]\right]\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)$  Compatibility

 • The Statistics[BarChart] and Statistics[ColumnGraph] commands were updated in Maple 2017.
 • The colorscheme option was introduced in Maple 2017.
 • The color option was updated in Maple 2017.