As often is the case, this article is prompted by a recent post on the SAS/GRAPH and ODS Graphics page communities page. A user wanted to create a Graph Table showing a bar chart with tabular data for each of the category values along the x-axis. The user was creatively using a VBAR overlaid with multiple VLINE statements using SAS 9.40M?. The VLINE statements were used to display the statistics.
I applaud the creativity of the user, who has clearly taken to heart the lesson that multiple plot statements can often be used creatively to build the graph you may want. Prior to SAS 9.4, this was one way to overlay additional textual data on a graph that contains a VBAR. However, with SAS 9.4, there is an easier way - AxisTable.
While we have discussed AxisTables in earlier articles, it seems worthwhile to review the subject. The graph above right shows how you can display multiple rows of data statistics aligned with the x-axis categories. The group values are clustered as shown for the box plot and in the table below it. Click on the graph for a higher resolution image.
Our goal is to create the graph above. Let us start with a cluster grouped box plot along with textual display of data. In the graph on the right, a box plot of Horsepower is displayed by Type with Group=Origin for the data set sashelp.cars. The group values are clustered side-by-side. An xAxisTable is used to display the associated values for Horsepower, also classified by Origin.
Note, since the CLASS option is used with the xAxisTable, the statistical values for the three levels of "Origin" are displayed stacked under each category on the x-axis. Each class value is displayed on the left.
With SAS 9.40M3, the CLASSDISPLAY option was added to allow the display of the class values in the clustered arrangement as shown on the right. Using CLASSDISPLAY=CLUSTER, values for each class are displayed side by side, and arranged in the same way as in the box plot. Now, the name of the variable is displayed on the left of the values. Note, we have used the COLORGROUP=Origin to color each value by the same variable to provide a visual that is easier to decode.
The benefit of this option is that multiple statistics can be displayed with such grouped plot statements. The graph on the right shows the mean values for Horsepower, Mpg_City and Mpg_Highway. More variables can be used if necessary.
SAS 9.40M3 Code for grouped Box Plot with Table.
title h=10pt 'Mean Auto Statistics by Type and Origin';
proc sgplot data=sashelp.cars(where=(type ne 'Hybrid')) noborder;
format mpg_city mpg_highway horsepower 3.0;
vbox horsepower / category=type group=origin name='a'
xaxistable horsepower mpg_city mpg_highway / class=origin
colorgroup=origin location=inside nostatlabel;
xaxis display=(nolabel noticks noline);
keylegend 'a' / location=inside position=topright across=1 title='';
Finally, the user wanted to add vertical divider lines (column border) to separate the column of values. Unfortunately, the AxisTable statement does not currently support column or row borders. However, the x-axis color bands could be used to create such a grouping as shown in the graph on the right. Click on the graph to see this more clearly. The banding intentionally uses a soft color, matching the color of the background. However, that can be controlled in the syntax.
A Graph Table is very effective for display of results of an analysis. The AxisTable is ideally suited to help create such visuals. Graph Tables such as the Survival Plot or the Forest Plot are popular examples of the usage of Axis Tables.
Full SAS 9.40M3 code for Graph Tables: GraphTableWithClass