Creating bar charts with log response axis has come up a few times in the past few days. Before we look into how we could do this, it would be worth pointing out the considerable opinion in the blogosphere against use of log response axes for bar charts. See BizIntelGuru and here.
Both GTL and SG procedures do not support log response axes for Bar Charts. Both include the zero value on the response axis for a bar chart. But when all data is positive, could this be possible?
I tried setting the min value on the axis to a value > zero, and then set the TYPE=log option (in SGPOLOT). No luck. Neither VBar nor Needle statement did not allow the usage of a log axis in this case.
With SAS 9.3, there is a way out using the HighLow statement. Of course, we summarize the data using proc Means, and then we can use the HighLow bar with Type=bar to get the following graph:
Bar Chart with Log Response Axis:
SAS 9.3 code:
title 'Log of Mean Horsepower by Type'; proc sgplot data=carsmean2; format mean 4.0; highlow x=type low=zero high=mean / type=bar highlabel=mean; yaxis type=log max=1000 offsetmin=0 label='Log of Mean' grid; xaxis display=(nolabel); run;
To use HighLow in proc SGPLOT, we need a variable with a small value to represent the lower end of the bar segment. Since the statement does not force a zero value on the axis, now we can specify Type=log on the yaxis statement. Note, I have specified max=1000 on the yaxis just to get a feel for all the log values in this case. HighLow plot can look like a needle or a bar, and I have set Type=Bar. We also added a bar label at the top using the HighLabel option.
If you really need to use log response axis on a bar chart, it could be done as shown above. But it would be worthwhile to consider if it should be done.
Full SAS 9.3 code: Bar_With_Log_Axis