07-17-2016 06:31 PM - edited 07-17-2016 10:18 PM
Using SAS 9.4, this simple code displays data erroneously. The bars are the wrong length, the reference lines at the wrong location.
Note how on the second chart, the second bar has a different length (but still wrong) and the reference line is placed correctly.
Any idea how to fix this?
data TEST; do PANEL=1 to 3; Y=1; X= 0.1; output; Y=2; X= 10; output; Y=3; X=10000; output; end; run; ods graphics on / width=640px height=320px; proc sgpanel data=TEST; panelby PANEL / novarname columns=3; hbar Y / response=X groupdisplay=cluster stat=median ; colaxis label='Time (seconds)' min=0.01 type=log logbase=10 ; refline 15/axis=X lineattrs=(pattern=shortdash color=darkred); refline 150/axis=X lineattrs=(pattern=shortdash color=green); refline 1500/axis=X lineattrs=(pattern=shortdash color=blue); run; proc sgpanel data=TEST; panelby PANEL / novarname columns=3; hbar Y / response=X groupdisplay=cluster stat=median ; colaxis label='Time (seconds)' min=0.01 type=log logbase=10 max=15; refline 15/axis=X lineattrs=(pattern=shortdash color=darkred); run;
07-18-2016 12:21 AM - edited 07-18-2016 12:23 AM
Is this expected behaviour? It seems pretty random to me.
I have no zeroes in my data, I specify the minimum value for the axis. And now I also need to specify the baseline option.
None of this should be necessary. Zeroes and negatives should be discarded (with a message in the log) and the rest should be automatic.
07-18-2016 05:59 AM
@ChrisNZsaid: None of this should be necessary. Zeroes and negatives should be discarded (with a message in the log) and the rest should be automatic.
I disagree. As you know,
lim as x-->0 log10(x)= -infinity
Therefore a bar chart that includes baseline zero would have to be infinitely long. Where would you expect this "automatic" cutoff to occur?
The documentation states that the default baseline for a bar chart is zero, in accord with established graphical priciples. Therefore setting a baseline seems like a reasonable thing to do.
By the way, Sanjay discusses this issue in a blog post from 2012 and links to a discussion about why bar charts with log axes are not a good idea. In a follow-up post, Sanjay presents alternative visualizations that make more sense.
07-18-2016 06:38 AM - edited 07-18-2016 07:04 PM
@Rick_SAS Sanjay discusses a pretty absurd example* where the data is between 100 and 300, which of course doesn't need a log axis. Since my data spreads from 0.01 to 2000, a log axis is pertinent, and a bar chart happens to be the most appropriate way to show *this data*. Bad ideas are like trash: One man's trash is another man's treasure. It all depends.
I can post my graph if you want to give some input and prove me wrong, but I am pretty comfortable about this.
As for cutting off the axis, where should the "automatic" cutoff to occur?
SAS/GRAPH has no issue answering this question, and does the right thing in my opinion: it scales according to the data. When a log axis is used, keeping the baseline at zero is plain silly, and SG procedures should be smart, not silly.
* This removes none of the value of Sanjay's ever instructive posts.
07-18-2016 06:50 AM - edited 07-18-2016 06:51 AM
In any case, the above is a matter of appreciation. There is no absolute right or wrong here, to each their own.
What is totally wrong is for SAS to display erroneous charts.
That is a no-no.
If the baseline is zero, and if it won't adapt automatically for a log axis, no graph should be produced.
Producing a fallacious graph is absolutely unacceptable imho.
The example I gave was obviously wrong, my real data not so.
So something must change: either the baseline is smarter, or the graph is not drawn.
Drawing graphs at random is clearly a defective behaviour.
07-18-2016 07:04 AM - edited 07-18-2016 07:15 AM
Alright my 2nd post vanished. I won't type the whole thing again.
Bottom line: SAS should not, ever, under any circumstances draw an erroneous graph.
In this case, either the baseline doesn't stay at zero when it sees a log axis, or no graph is drawn. Drawing a fallacious graph for whatever reason is simply defective behaviour.
07-18-2016 09:33 AM - edited 07-18-2016 09:37 AM
I agree SAS should not display a wrong graph. There are many notes in the log about the use of this log axis with "zero" in the data. The log says it is reverting to "Linear" axis, but the graph is still showing a log axis and incorrect graph. Please report this issue to Tech Support.
Separately, my posts about the "Log Axis for Bar Charts" is not dependent on the data. This is generally considered a bad idea because the "length" of the bar is what gives the eye the cue for magnitude comparisons. When the scale is non-linear, that "length" cue is distorted. It is considered better to use other plots that do not provide such a cue when using log scale, as commented by John Munoz and others.
07-18-2016 06:55 PM - edited 07-18-2016 07:07 PM
1- About SAS's behaviour:
>There are many notes in the log about the use of this log axis with "zero" in the data
Yes there are. Like this:
NOTE: Log axis cannot support zero or negative values in the data range. The axis type will be changed to LINEAR.
Useless notes as 1) I don't have zero or negative values in my data and 2) the axis is not changed to linear.
This whole log axis implementation area has room for improvement.
2- About the graph:
I know the bar lengths are misleading, but not much more than dot positions. On a log axis, a dot twice as far is not twice the value. That's life with log axes. I don't see how length is much worse than distance/position.
The best way to deal with this scaling issue is to display minor grid lines when using log axes imho, and to use reference lines to highlight differences or thresholds.
Bars are more useful for me here as they are grouped, show small differences well, and dots would be more difficult to read with no appreciable benefit in meaningfulness.
3-I'll open a track for both the defective log message and the fallacious graph.
I'd much prefer if you guys could pick the ball when this kind of issue is raised in these forums, as I often have many tracks open at any point in time, and SAS OZ must hate me, and I sometimes feel that I'm working for SAS QA.
07-20-2016 05:49 PM
Moved the discussion about SAS support and exchanges in the communities to the Community Matters board.
07-20-2016 06:11 PM
Fyi, here is an draft of a graph.
I am working on the third edition of
and comparing different ways to "merge" data (SAS's implementation of "exists" in SQL is not the best btw) for different purposes.
Need further help from the community? Please ask a new question.