Data visualization with SAS programming

Integers on Axis

Reply
Super User
Posts: 19,008

Integers on Axis

Hi All,

In GCHART or GPLOT is there a way to format the axis to be integers?

Ie my points are (1.2, 10.3) (2.4,11.3) (8.5, 9.2)

I'd the like the graph axis to be 1 2 3 ... 10 rather than 1.0 to 10.0

I'm using annotate to label certain points but when I include a format statement in the gchart the annotate variables are also losing their decimal point.

Thanks.

PROC Star
Posts: 7,428

Integers on Axis

Would the method described at http://communities.sas.com/message/26127#26127 suffice?

Super User
Posts: 19,008

Integers on Axis

I don't think so...because format 8. changes the annotate values it will change the values being labelled as well, and that's not what I'm looking for.

I need to label points and separately label the axis with specific values.

I see that this is the GTL for 9.3 but I haven't been able to find anything related to GPLOT or GCHART.

Thanks though!

SAS Employee
Posts: 977

Integers on Axis

I'm not sure I understand the question exactly, but you can control the format of the values used on the gplot axis tickmarks (and the gchart response axis) by applying a format - either to the data set, or specify it in the gplot.

And when annotating text values, the annotated text will be whatever you stuff into the 'text' variable - if you apply a format (such as using the put() function when you create the text variable) then the annotated text will be formatted in that way.

Here is an example:

data foo;
input x y;
datalines;
1.2 10.3
2.4 11.3
8.5 9.2
;
run;

data foo_anno; set foo;
function='label'; position='2'; xsys='2'; ysys='2'; color='red';
text=put(y,comma5.0);
run;

proc gplot data=foo anno=foo_anno;
format y comma5.0;
format x comma5.0;
plot y*x;
run;

Super User
Posts: 19,008

Integers on Axis

Thanks Rob,

I was mistaken, the labels are being output by a symbol and pointlabel statement rather than annotate, the annotate is used for something else.

Is there a way to format to apply specific formats using the symbol or axis statement?

SAS Employee
Posts: 977

Integers on Axis

Well, for the axes, I would definitely use the format in the data, or the format in the proc gplot, to control the format of the numbers in the axes.

To get the maximum flexibility in the pointlabel, I could create a new text variable in the data set (similar to the one I created in the annotate data set), and use the put() function and whatever format you like (and even add extra characters if desired), and then specify that as the variable to use as the pointlabel.


data foo;
input x y;
text=put(y,comma5.0);
datalines;
1.2 10.3
2.4 11.3
8.5 9.2
;
run;

symbol value=dot height=2 color=red
     pointlabel=("#text" h=2.2 c=gray55 font="albany amt/bold");

proc gplot data=foo;
format y comma5.0;
format x comma5.0;
plot y*x;
run;

Super User
Posts: 19,008

Re: Integers on Axis

The following seems to give me what I want the easiest.

data foo;

input x y;

datalines;

1.2 10.3

2.4 11.3

8.5 9.2

;

run;

data foo_anno; set foo;

function='label'; position='2'; xsys='2'; ysys='2'; color='red';

text=put(y,comma5.1);

run;

axis1 value=('1' '2' '3' '4' '5' '6' '7' '8' '9' '10');

proc gplot data=foo anno=foo_anno;

plot y*x/haxis=axis1;

run;

Rob's solution is probably more maintainable, but this is a quick fix at the moment.

Thanks!

SAS Employee
Posts: 977

Re: Integers on Axis

This quick-fix (hard-coding values in the axis statement) is pretty dangerous, especially since you're letting the axis auto-scale -- if the data you're plotting ever changes (and causes the axis to auto-scale another way, say from 1 to 5), then these hard-coded axis values would become wrong.

Super User
Posts: 19,008

Re: Integers on Axis

Thanks for the heads up.

I also didn't mark my own answer as correct, instead I said assumed answered :smileyconfused:

Ask a Question
Discussion stats
  • 8 replies
  • 2341 views
  • 6 likes
  • 3 in conversation