Sample 24932: Display the left and right axes with a single combined legend with PROC GPLOT
This sample uses PLOT and PLOT2 statements with PROC GPLOT to create a graph with two vertical axes. A dummy variable with all missing values is added to the data set in order to produce a single combined legend.
To produce a single combined legend, the SYMBOL3 and SYMBOL4 statements in the sample code are identical. While the third entry in the legend actually represents the new dummy variable added to the data set, the use of a LEGEND statement makes it appear as though the third legend entry represents the variable plotted by the PLOT2 statement.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
This sample uses PLOT and PLOT2 statements with PROC GPLOT to create a graph with two vertical axes. A dummy variable with all missing values is added to the data set in order to produce a single combined legend.
To produce a single combined legend, the SYMBOL3 and SYMBOL4 statements in the sample code are identical. While the third entry in the legend actually represents the new dummy variable added to the data set, the use of a LEGEND statement makes it appear as though the third legend entry represents the variable plotted by the PLOT2 statement.
The graphics output in the Results tab was produced using SASĀ® 9.2. Submitting the sample code with releases of SAS prior to SAS 9.2 might produce different results.
/* Set the graphics environment */
goptions reset=all cback=white border
htitle=12pt htext=10pt;
/* Create the input data set A where Y3 is a */
/* dummy variable containing all missing values */
data a;
input X Y1 Y2 Y3 Y4;
datalines;
1 2 50 . 100
2 2 50 . 400
3 2 50 . 200
;
run;
/* Create symbol definitions where SYMBOL3 */
/* and SYMBOL4 are identical. */
symbol1 i=j v=dot c=vibg w=1 h=1.5;
symbol2 i=j v=dot c=depk w=1 h=1.5;
symbol3 i=j v=dot c=mob w=1 h=1.5;
symbol4 i=j v=dot c=mob w=1 h=1.5;
/* Create axis definitions */
axis1 order=(0 to 5 by 1);
axis2 order=(0 to 100 by 10) minor=none
label=('Y1 and Y2');
axis3 order=(0 to 1000 by 100) minor=none;
/* Customize the legend to make the third */
/* entry appear as though it represents */
/* variable Y4 plotted by the PLOT2 */
/* statement. */
legend1 value=(tick=3 'Y4') across=1;
/* Add a title to the graph */
title1 'Combined Legend with PLOT and PLOT2';
/* Create the graph */
proc gplot data=a;
plot y1*x=1 y2*x=2 y3*x=3 / overlay haxis=axis1
vaxis=axis2 legend=legend1;
plot2 y4*x=4 / vaxis=axis3 ;
run;
quit;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.

This sample uses PLOT and PLOT2 statements with PROC GPLOT to create a graph with two vertical axes. A dummy variable with all missing values is added to the data set in order to produce a single combined legend.
| Type: | Sample |
| Topic: | SAS Reference ==> Procedures ==> GPLOT Query and Reporting ==> Creating Reports ==> Graphical ==> Graph Elements ==> Legends
|
| Date Modified: | 2005-08-31 03:03:20 |
| Date Created: | 2004-11-11 11:08:02 |
Operating System and Release Information
| SAS System | SAS/GRAPH | All | n/a | n/a |