When the plot statements are specified in a 2D overlay-type
layout, the AUTOALIGN= option can be used to automatically position
an inside legend. AUTOALIGN= selects a position that avoids or minimizes
collision with plot components.
The AUTOALIGN=
option enables you to specify an ordered list of potential positions
for the legend. The list contains one or more of the following keywords:
TOPLEFT, TOP, TOPRIGHT, LEFT, CENTER, RIGHT, BOTTOMLEFT, BOTTOM, and
BOTTOMRIGHT. In the following example, we know that the best position
for an inside legend is TOPRIGHT or TOPLEFT. Because the AUTOALIGN=
option specifies a list of preferred positions, the first of the listed
positions that does not involve data collision is used. Had the histogram
been skewed to the right, the TOPLEFT position would be used.
layout overlay;
histogram Weight / name="sp";
densityplot Weight / kernel()
legendlabel="Kernel Density"
name="kde";
discretelegend "kde" /
location=inside
autoalign=(topright topleft) ;
endlayout;
When the
parent layout contains only scatter plots, you can fully automate
the selection of an internal position by specifying AUTOALIGN=AUTO.
This is a "smart" option that automatically selects a position where
there is no (or minimal) collision with plot components. The AUTOALIGN=AUTO
option selects a position for you. Note that positions that are not
possible with HALIGN= and VALIGN= might be used.
layout overlay;
scatterplot X=Height Y=Weight / name="sp" group=sex;
discretelegend "sp" / location=inside autoalign=auto ;
endlayout;