BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ChrisNZ
Tourmaline | Level 20

 

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;

 

SGPanel40.png

 

SGPanel41.png

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

The procedure gets confused because it can't start the bar at zero on a log axis. Add the baseline=0.01 option to the hbar statement.

PG

View solution in original post

11 REPLIES 11
PGStats
Opal | Level 21

The procedure gets confused because it can't start the bar at zero on a log axis. Add the baseline=0.01 option to the hbar statement.

PG
ChrisNZ
Tourmaline | Level 20

Thank you!    🙂


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.

Rick_SAS
SAS Super FREQ

   @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,

log10(0.01)= -2, 

log10(0.001)= -3, 

log10(0.0001)= -4, 

...

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.

ChrisNZ
Tourmaline | Level 20

@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. 🙂

ChrisNZ
Tourmaline | Level 20

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.

ChrisNZ
Tourmaline | Level 20

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.

 

Jay54
Meteorite | Level 14

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.

ChrisNZ
Tourmaline | Level 20

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.

 

 

 

 

ChrisHemedinger
Community Manager

Moved the discussion about SAS support and exchanges in the communities to the Community Matters board.

ChrisNZ
Tourmaline | Level 20

Fyi, here is an draft of a graph.

 

I am working on the third edition of

https://www.amazon.com/High-Performance-SAS-Coding-Christian-Graffeuille/dp/1512397490

and comparing different ways to "merge" data (SAS's implementation of "exists" in SQL is not the best btw) for different purposes.

 

Gorgeous no? 😉

 

 img0.png

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 11 replies
  • 3327 views
  • 5 likes
  • 5 in conversation