ColorCodeObsAndDrawLegend

Prototype

void ColorCodeObsAndDrawLegend( Plot plot, Matrix mVarName, Matrix mColorMap, Matrix mLegendSizeFrac, Matrix mLocation )

Parameters

Plot plot
The plot to which the legend will be added.

Matrix mVarName
The name of a variable in the DataObject connected to the plot. The values of this variable determine the color of observations. If the variable is nominal, a discrete color ramp is created; otherwise, a continuous color ramp is created.

Matrix mColorMap
A k x 3 matrix of RGB values or a k x 1 vector of hexadecimal color values. These values are used to color the observations and define the color ramp.

Matrix mLegendSizeFrac
A numeric vector of length 2 that specifies the size of the legend. mLegendSizeFrac[1] is a number in [0.01, 1] that specifies the width of the legend as a percentage of the plot width. mLegendSizeFrac[2] is a number in [0.01, 1] that specifies the height of the legend as a percentage of the plot height.

Matrix mLocation
A text string that specifies the position of the legend within the plot. This string has the form "PX", where P is either I (inside the Plot Area) or O (outside the Plot Area), and X is either L (left), R (right), T (top), or B (bottom). For example, common choices are "IL" (left side of the Plot Area), or "OR" (in the right graph margin). The strings "OL" and "OB" are not supported.

Remarks

This module color-codes observations according to values of a single variable using a user-defined color blend, then draws a continuous legend on the plot. A continuous legend is a color ramp with a set of labels. The legend indicates how colors in the plot relate to values of the mVarName variable.

The module also computes tick labels based on the values of the mVarName variable.

This module calls the ColorCodeObs and DrawContinuousLegend modules. The first color is assigned to the minimum value of mVarName and the last color is assigned to the maximum value of mVarName.

Example
declare DataObject dobj;
dobj = DataObject.CreateFromFile( "Iris" );
declare ScatterPlot plot;
plot = ScatterPlot.Create( dobj, "SepalLen", "SepalWid" );
plot.SetMarkerSize( 7 );

Colors = BLUE // CYAN // YELLOW // RED ;
ColorMap = BlendColors( IntToRGB(Colors), 64 );
LegendSizeFrac = {0.1, 0.7};
run ColorCodeObsAndDrawLegend( plot, "PetalLen", ColorMap,
                               LegendSizeFrac, "OR" );
See Also

ColorCodeObs
DrawContinuousLegend