Data visualization with SAS programming

How to create uneven tick marks on graph axis?

Accepted Solution Solved
Reply
Occasional Contributor CEB
Occasional Contributor
Posts: 6
Accepted Solution

How to create uneven tick marks on graph axis?

I want uneven tick marks on my graph axis. This comes up frequently. Currently I wish I could create a log axis over a small range like 2, 2.5, 3, 4, 5 (that is, much less than one decade). It has also come up with dates because of the varying length of the months, and with nominal values such as a tensile strength graph for screws of size 4-40, 6-32, 8-32 and 10-24.

I always get evenly spaced ticks. What was a smooth curve becomes kinked so that the tick marks can be evenly spaced, not what I want.

This turned up in the Knowledge Base:

"Problem Note 1750: The ORDER= option might be ignored with the JAVA device driver
   

The ORDER= option on an AXIS statement might be ignored when using the JAVA device driver."

This makes me think that uneven ticks are supposed to work and just malfunction in some situations. However I have not found any situation where it works as I want. I have been using SAS GRAPH procs GPLOT and GCONTOUR and using the default graph window as an output, or outputting to graphics files such as GIF and BMP.

One workaround would be to suppress tick marks and labels, and use ANNOTATE instead, but it's a lot of extra work and opportunity for error. Unfortunately I just distributed an embarrassing graph error using this approach.


Accepted Solutions
Solution
‎03-21-2012 11:48 AM
SAS Employee
Posts: 967

How to create uneven tick marks on graph axis?

data foo;
input x y;
datalines;
1 5
3 6
7 7
10 8
;
run;

data anno_axis;
input x_value;
datalines;
1
1.25
1.5
2
2.5
3.2
4
5
6.4
8
10
;
run;


data anno_axis; set anno_axis;
/* text */
function='label';
xsys='2'; ysys='1'; x=x_value; y=-3;
position='5'; text=trim(left(x_value)); output;
/* tickmark */
function='move'; x=x_value; y=0; output;
function='draw'; y=-1; color='black'; size=.01; output;
run;

data ignore_error;
function='seterror'; size=1000; output;
function=''; size=.; output;
run;
data anno_axis; set ignore_error anno_axis;
run;

goptions cback=white;

axis1 value=(color=white) major=none minor=none order=(1 10) logbase=10 logstyle=expand;

symbol1 value=dot interpol=join;

proc gplot data=foo anno=anno_axis;
plot y*x=1 / haxis=axis1;
run;

View solution in original post


All Replies
SAS Employee
Posts: 967

How to create uneven tick marks on graph axis?

I don't typically use this technique, but I think (not 100% sure) that when you specify non-evenly spaced values in the axis order=, it (basically) treats the axis as a character/categorical, rather than as a continuous numeric axis.  I think the caveat here is that you would need to specify *every* value in the legend order=, which could be quite cumbersome. 

Here's a simple example that demonstrates this way to do it:

data foo;
input x y;
datalines;
1 5
3 6
7 7
15 8
;
run;

axis1 order=(1 3 7 15);


symbol1 value=dot interpol=join;


proc gplot data=foo;
plot y*x=1 / haxis=axis1;
run;

Occasional Contributor CEB
Occasional Contributor
Posts: 6

How to create uneven tick marks on graph axis?

Thanks, Robert, but that didn't seem to do it. When I tried, the tick marks were still placed spaced equal distances apart though they represent uneven steps in the data space. Here's my log window content (I tried the order with and without commas because my habit is to use them, but it didn't matter). I used the same sequence of numbers for my values of x and for specifying the order, so each unevenly spaced point should have had a tick mark directly below it. As you can see, SAS recognizes I am asking for uneven spacing - it just doesn't give it.

1

2 data test;

3 input x;

4 y = x ** 1.8;

5 cards;

NOTE: The data set WORK.TEST has 8 observations and 2 variables.

NOTE: DATA statement used (Total process time):

real time 1.15 seconds

cpu time 0.06 seconds

14 ;

15 run;

16

17 axis1 order = (1,1.5,2,2.5,3,5,7,10);

18 proc gplot;

19 plot y*x / haxis = axis1;

20 run;

WARNING: The intervals on the axis labeled x are not evenly spaced.

WARNING: No minor tick marks will be drawn because major tick increments have been specified in uneven or unordered intervals.

21

22 axis1 order = (1 1.5 2 2.5 3 5 7 10);

NOTE: There were 8 observations read from the data set WORK.TEST.

NOTE: PROCEDURE GPLOT used (Total process time):

real time 55.64 seconds

cpu time 0.78 seconds

23 proc gplot;

24 plot y*x / haxis = axis1;

25 run;

WARNING: The intervals on the axis labeled x are not evenly spaced.

WARNING: No minor tick marks will be drawn because major tick increments have been specified in uneven or unordered intervals.

SAS Employee
Posts: 967

How to create uneven tick marks on graph axis?

So, you want the axis to be correctly/proportionally spaced, but you want to suppress the default tickmark values, and specify a list of values along the axis to place labels at(?)

I think the only way to do that with gplot is probably to use an axis statement to suppress the default values (for example, make them the same color as the background ... this keeps the space you need for the new values), and then annotate the values you want, in the positions you want.

Here's a short example:

data foo;
input x y;
datalines;
1 5
3 6
7 7
15 8
;
run;

data anno_axis;
input x_value;
datalines;
1.5
5.5
10
;
run;
data anno_axis; set anno_axis;
xsys='2'; ysys='1';
x=x_value; y=-3;
function='label'; position='5'; text=trim(left(x_value));
run;

goptions cback=white;

axis1 value=(color=white);

symbol1 value=dot interpol=join;

proc gplot data=foo anno=anno_axis;
plot y*x=1 / haxis=axis1;
run;

Occasional Contributor CEB
Occasional Contributor
Posts: 6

How to create uneven tick marks on graph axis?

You correctly understand the axis spacing and the values and their placements. I would go a step further and want the tick marks themselves to be placed arbitrarily, too. For example I like to create a log axis on which the values are written as "1   1.25   1.5   2   2.5   3.2   4   5   6.4   8   10", which your approach will do, but I also like the ticks (and grid lines) to be accurately placed, which means slightly uneven spacing on the graph.

I think I remember working this out with annotate data sets, and getting mixed results with drawing lines slightly outside the data space to create the tick marks, but mostly I have taken the easy way of letting these values get placed at evenly spaced locations (which is pretty close).

I like this sequence of values because it represents 10^z where z = 0 to 1 by 0.1. I have memorized it and a few other folks here have also done so. This lets us take logarithms in our head to one decimal place accuracy.

Solution
‎03-21-2012 11:48 AM
SAS Employee
Posts: 967

How to create uneven tick marks on graph axis?

data foo;
input x y;
datalines;
1 5
3 6
7 7
10 8
;
run;

data anno_axis;
input x_value;
datalines;
1
1.25
1.5
2
2.5
3.2
4
5
6.4
8
10
;
run;


data anno_axis; set anno_axis;
/* text */
function='label';
xsys='2'; ysys='1'; x=x_value; y=-3;
position='5'; text=trim(left(x_value)); output;
/* tickmark */
function='move'; x=x_value; y=0; output;
function='draw'; y=-1; color='black'; size=.01; output;
run;

data ignore_error;
function='seterror'; size=1000; output;
function=''; size=.; output;
run;
data anno_axis; set ignore_error anno_axis;
run;

goptions cback=white;

axis1 value=(color=white) major=none minor=none order=(1 10) logbase=10 logstyle=expand;

symbol1 value=dot interpol=join;

proc gplot data=foo anno=anno_axis;
plot y*x=1 / haxis=axis1;
run;

Occasional Contributor CEB
Occasional Contributor
Posts: 6

How to create uneven tick marks on graph axis?

Robert, thanks for the gold plated answer. This definitely covers it all! -Chris

Occasional Contributor kas
Occasional Contributor
Posts: 8

Re: How to create uneven tick marks on graph axis?

I came across this thread because I was trying to work out the same thing. So, I tried it and the presentation turned out perfect.  I had always avoided this method because of the ERROR generated in the NOTE in the log.

Is there a way to change the message in the NOTE?  My site gets all worked up when 'ERROR' appears in a log. 

Perhaps the NOTE could read

'NOTE:  The ANNOTATE dataset is not happy with the values outside the boundaries but it is fine'

Something like that?

SAS Employee
Posts: 967

Re: How to create uneven tick marks on graph axis?

I don't know of a way to change the contents of the 'Note' printed in the SAS log.

It's probably appropriate for it to mention the word 'error' because of the way it handles it ... For example, by default if it encounters 20 of these "error" notes, then it will stop processing the annotate commands (note that I increase the annotate 'seterror' to 1000 to avoid this).  Since I get the desired graph, it's just one of those things I've learned to live with :-)

SAS Super FREQ
Posts: 890

How to create uneven tick marks on graph axis?

The ability to do uneven tick values is something that the SGPLOT, SGPANEL, and GTL support naturally. See pages 12-13 of this paper for more details: http://support.sas.com/resources/papers/proceedings09/324-2009.pdf. Let me know if you have any more questions about it.

Thanks!
Dan

Occasional Contributor
Posts: 8

Re: How to create uneven tick marks on graph axis?

Hi Dan,

The ability to do uneven tick values is something that the SGPLOT, SGPANEL, and GTL support naturally. See pages 12-13 of this paper for more details: http://support.sas.com/resources/papers/proceedings09/324-2009.pdf. Let me know if you have any more questions about it.

I want to practise the uneven tick values in the figure 22 in your article, but where is dataset (physical end=eof?) you used in page 14, how to get the dataset?

thanks!

Muyi

Valued Guide
Posts: 763

Re: How to create uneven tick marks on graph axis?

hi ... this topic was discussed on SAS-L a while back ...

listserv.uga.edu/cgi-bin/wa?A2=ind0807C&L=sas-l&P=R20332

attached is some SAS code I posted (with a few edits) and the output that's produced

it was also discussed later ...

listserv.uga.edu/cgi-bin/wa?A2=ind1008C&L=sas-l&P=R11207

and that discussion ended with an example of using SGPLOT to solve the problem (as has been mentioned in this thread)

Attachment
Attachment
SAS Super FREQ
Posts: 1,081

Re: How to create uneven tick marks on graph axis?

Please see Dan's article on custom axis tick values using SGPLOT procedure.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 12 replies
  • 4175 views
  • 0 likes
  • 7 in conversation