Changing the Appearance of Vertical Bar Charts using the HPOS Option
From sasCommunity
If you use PROC GCHART to create a vertical bar chart, you may find that SAS/Graph produces a very narrow graphic. You might not know how to get the PROC to use more of the graphics output area so the chart doe not looked squeezed into the center of the page. Here is an example that uses the data set SASHELP.AIR.
goptions reset=all ftext='arial' htext=2 gunit=pct; axis1 label=(a=90 'INTERNATIONAL AIRLINE TRAVEL MILES (1,000s)'); pattern v=s c=green; title1 h=3 "SASHELP.AIR DEFAULT PLOT --- V9.1.3, WINDOWS XP"; proc gchart data=sashelp.air; vbar date / discrete outside=sum type=sum sumvar=air coutline=blue raxis=axis1 noframe ; format date year.; run; quit;
To see the output from this procedure generated in V9.1.3 and Windows XP, click here. The bar chart is very narrow. Also, the OUTSIDE=SUM option is used to put a statistic at the top of each bar, but no text appears and the LOG contains a warning message: The VBAR/VBAR3D chart for DATE could not be labeled because the labels are wider than the bars.
It is easy to modify the appearance of this chart by using the HPOS option. Here is the above SAS code with only one modification, HPOS=10 in the GOPTIONS statement.
goptions reset=all hpos=10 ftext='arial' htext=2 gunit=pct; axis1 label=(a=90 'INTERNATIONAL AIRLINE TRAVEL MILES (1,000s)'); pattern v=s c=green; title1 h=3 "SASHELP.AIR WITH HPOS=10 --- V9.1.3, WINDOWS XP"; proc gchart data=sashelp.air; vbar date / discrete outside=sum type=sum sumvar=air coutline=blue raxis=axis1 noframe ; format date year.; run; quit;
To see the output from this procedure generated in V9.1.3 and Windows XP, click here. The bar chart now takes up the entire page and the total miles traveled in each year appears above each bar. The following SAS code uses HPOS=40 and adds a few more statements to enhance the appearance.
goptions reset=all hpos=40 ftext='arial' htext=2 gunit=pct; axis1 label=(a=90 'INTERNATIONAL AIRLINE TRAVEL MILES (1,000s)'); pattern v=s c=green; title1 h=4 "SASHELP.AIR WITH HPOS=40 --- V9.1.3, WINDOWS XP" ls=2; title2 a=90 ls=2; title3 a=270 ls=1; footnote ls=1; proc gchart data=sashelp.air; vbar date / discrete outside=sum type=sum sumvar=air space=0 coutline=grayaa raxis=axis1 noframe ; format date year.; run; quit;
To see the output from this procedure generated in V9.1.3 and Windows XP, click here. This chart is much improved over the default and makes better use of the available output area. In addition to the HPOS option, some extra TITLE statements add white space on the left and right of the chart. The LS option on each TITLE statement adds space above the titles. Since two of the titles are rotated, one appears on the left (a=90) and the other on the right (a=270). There is no text in either title, so just white space is added. Similarly, the FOOTNOTE adds white space at the bottom of the chart. A SPACE option in GCHART removes the space between the bars and the outline color is now light gray (COUTLINE=GRAYAA).
In V9.2, the default appearance of the vertical bar chart is much improved over that in V9.1.3. To see the output produced in V9.2 using the original SAS code without any HPOS option, click here. The appearance can still be improved by using the above SAS code with HPOS=40 plus the additional 'tweaks' (added white space, etc.). To see the output from this procedure generated in V9.2 and Windows XP, click here.
You can read more about HPOS starting by clicking here. After reading that page, make sure to proceed to the discussion of Procedure Output and the Graphics Output Area. The HPOS option is also discussed in a neat paper by Jeff Cartier that you can access by clicking here . To see the HPOS discussion, go to page 7.
If you have any questions about this posting, you are welcome to send me a note by clicking here ... email Mike.
