|
HOW CAN I PLACE TWO CHARTS ON A PAGE WITH A SINGLE TITLE? INPUT: I want to place multiple charts on a page. All of the charts represent the same variables, but for different time periods, so I only need a single legend, rather than a separate legend for each chart. Is there a way to do this? OUTPUT: One way to produce multiple charts with a single legend is to create the charts with PROC GCHART and replay them in a panel with PROC GREPLAY. You can use AXIS and LEGEND statements along with PROC GCHART statement options to position the graphs and produce a single legend. The following example illustrates the process. Suppose you have quaqrterly sales data for two store locations across two years. The data are read in as the variables CITY, YEAR, QUARTER, and SALES as follows:
You want to create a vertical bar chart for each year, with each bar representing the total sales for a city, with the sales subdivided by quarter. Although there will be two charts, each with its own axis you want a single legend, representing the values for QUARTER, and a single title. To produce a single centered title and legend, you can create two separate graphs and replay them into a template containing a full-size panel, effectively overlaying the graphs. One graph includes the title, subtitle, and legend, and positions the chart to the left side of the output. The second graph has a subtitle, but no title or legend, and positions the bar chart on the right side. Steps for creating the graphs follow. First, create a format to be used with the Quarter variable, and specify patterns for the bars in the charts.
proc format;
value quarterf
1='Winter'
2='Spring'
3='Summer'
4='Fall';
run;
pattern1 c=black v=s;
pattern2 c=gray66 v=s;
pattern3 c=grayaa v=s;
pattern4 c=graycc v=s;
Now, use the VBAR statement in PROC GCHART to create a chart for 1991.
goptions ftext=swiss;
proc gchart;
where year=1991;
vbar city/subgroup=quarter sumvar=sales raxis=axis1 maxis=axis2 legend=legend1;
axis1 origin=(15 pct, 20 pct) label=none;
axis2 origin=(15 pct, 20 pct) length=30 pct label=none;
legend1 cshadow=black frame label=none value=(j=l) shape=bar(5,2);
Title h=8 pct 'Yearly Sales by Quarter';
title2 h=5 pct m=(25 pct,+0 pct) '1991';
format quarter quarterf.;
run;
The statements and options above have the following effect:
The following statements produce the second chart:
where year=1992;
vbar city/subgroup=quarter sumvar=sales raxis=axis1 maxis=axis2
nolegend;
axis1 origin=(60 pct, 20 pct) label=none;
axis2 origin=(60 pct, 20 pct) length=30 pct label=none;
title h= 8 pct ' ';
title2 h=5 pct m=(70 pct, +0 pct) '1992';
run;
The statements and options above have the following effect:
You can then use PROC GREPLAY to display both graphs on the same page. In this case, use the template named WHOLE, from the SASHELP.TEMPLT catalog. The WHOLE template is a single panel that takes up the whole graphics area. Use the TREPLAY statement to replay both graphs into the same panel. proc greplay igout=gseg nofs; tc sashelp.templt; template whole; treplay 1:1 1:2; quit;This produces the final graph:
By modifying the program slightly, you can display more than two charts with a single legend and title. You can also use the same approach to combine multiple graphs produced by other SAS/GRAPH procedures. |