B.16 Plotting
BayES can produce five types of plots:
-
histograms
-
scatter plots (y versus x)
-
correlograms (acf plots)
-
line plots (y versus x or the values of y versus their row index)
-
kernel density estimates
There are five basic plotting functions in BayES, each one of which corresponds to a plot type: hist(), scatter(), acf(), plot(), and kden(). These functions are documented in the following table and, in their simple use, they draw their respective plots on a new figure window that they initiate. For example, execution of a statement of the form:
will create a new figure window and plot the values contained in vector y versus the values contained in vector x. All five basic plot functions return the title of the figure window on which they are plotting. If, for example, the following statement is executed, while no figure windows are currently open:
apart from creating a new figure window and displaying the plot, BayES will create a new string item in the current workspace, with id value figureTitle and content "Figure 1".
The five basic plotting functions differ in the number of numerical arguments they take, but all of them have the following optional arguments:
- "title"
- "xlabel"
- "ylabel"
- "grid"
- "colors"
These arguments, if provided, must be given after the numerical arguments of the plotting function, separated by commas and in any order. For example, the statement:
produces a scatter plot of the values contained in vector y versus the values in vector x and sets the plot’s title and x-axis label. Finally, it requests a grid to be drawn on the figure. The statement is equivalent to:
"title", "xlabel" and "ylabel" must be followed by the assignment operator, ‘=’, and a string that specifies the corresponding option. "grid" must be followed by the assignment operator and either the string "on" or the string "off".
The "colors" option specifies the colors to be used in the graph. Its value must be a matrix with three columns and all elements between zeros and one. Each row of this matrix specifies a color in RGB (red-green-blue) format, with the first row specifying the background color, the second the color of the axes and the text labels and the remaining rows specifying the colors used for plotting the data. For example, the statement:
plots a scatter plot of the values in y versus the values in x and sets the graph’s background color to black (0, 0, 0), the color of the axes and labels to red (1, 0, 0) and the color of the markers used to represent the data to magenta (0.5, 0, 0.5).
For the remainder of this section the five optional arguments described above will be represented by <plot options>.
Multiple plots per figure window can be drawn by combining the five plotting functions with the multiplot() and subplot() functions. For example, the statement:
will initialize and display a figure window that can plot 6 plots, across 2 rows. At this stage, this window will be empty and need to be populated by actual plots. Submitting the statement:
after a call to multiplot() will plot the values in y versus the values in x in row 2, column 1 of the figure window whose title bar displays the same string as the value of figureTitle. Similar calls to other plotting functions can be used to populate the remaining spaces of the multiple-plot figure window. Notice that the subplot() function must be provided as the first argument of a plotting function. If the call to plot() in the previous statement did not include a call to subplot(), the plot would be created in a new figure window, even after an empty multiple-plot window has been initialized. Thus, the call to subplot() is optional and, for the remainder of this section, any possible complete call to this function will be denoted by <subplot options>. Note that subplots within graphs must have the same background color. The overall background color in graphs that contain multiple subplots is the background color specified for the subplot located at the upper left corner of the graph.
The close() function can be used to close a figure window programmatically. For example the statement:
will close the figure window with “Figure 1" displayed in its title bar, while the statement:
will close all currently open figure windows. The contents of figure windows can be exported using the export() function, which is documented in section B.4.
BayES limits the maximum number of figure windows that can be open at any given time. If a new figure window is requested when this maximum number has been reached then BayES produces an error. The function maxfigures() can be used to change the maximum number of figure windows using a statement like:
Finally, plotdraws() is a utility function that can be used to create a multiple-plot figure window and plot four types of plots of the draws from the posterior distribution of a parameter from a model in the current workspace. Because this function works on the results of models only, it is documented in section B.14.
Syntax | Arguments and performed function |
W
=
acf(
<subplot
options>, | Plots a correlogram for the values in vector y. lags sets the maximum lags for which
the correlation coefficients are calculated and plotted. If lags is not provided then its
value is set equal to 30.
|
W
=
hist(
<subplot
options>, | Plots a histogram of the values in vector y. bins is the number of bins to be used for
the histogram. If bins is not provided then its optimal value is calculated
internally.
|
W
=
kden(
<subplot
options>, | Plots the kernel density of the values in y. If y contains more than one column
then each column is treated as a separate variable; the kernel density is
estimated separately and plotted using a different line color on the same
plot.
|
W
=
plot(
<subplot
options>, | Plots a line plot of the values in y versus either the values in x (if provided) or the
row index of each value. If y contains more than one column then each column is
plotted as a different variable versus x or the row index and using a different line
color for each variable.
|
W
=
scatter(
<subplot
options>, | Plots a scatter plot of the values in y versus the values in x. If y contains
more than one column then each column is plotted as a different variable
versus the values in x and using a different color and mark symbol for each
variable.
|
W = multiplot(i, j) | Initializes a figure window on which multiple plots can be drawn and sets its
dimensions: i is the number of plots that can be drawn per column and j is the
number of plots that can be drawn per row. That is, the window can be thought of
as an area consisting of i rows and j columns, with each cell being able to
accommodate a individual plot.
see also subplot |
subplot(s, i, j) | This function does not form a complete statement on its one and it can only be used as the first argument to the five basic plotting functions: hist(), scatter(), acf(), plot(), and kden(). When these plotting functions contain a call to subplot(), instead of plotting the respective plot on a new figure window, they plot it on the window whose title bar displays the string in s. i specifies the row of the figure window on which the plot is displayed and j the column of this window.
see also multiplot |