Data visualization with SAS programming

Display x-axis tick mark values in boxplot

Reply
Contributor
Posts: 49

Display x-axis tick mark values in boxplot

Dear all,

I want to get a boxplot for my data which has 20 boxes. I used axis statement to rename the value of x-axis tick marks to center1 tocenter20. I like all of them appear in the x-axis. But boxplot procedure only give center1, center3 till center19. Is it due to too many tick marks so theycan fit in the x-axis? And is there any way to solve this problem and let 20centers all show up in x-axis? Below is my data, the code to generate boxplot follows:

/***data***/

data sims;

call streaminit(16812);

array o_sfc osfc1-osfc20;

mu=200;

disp=5;

alpha= mu / (disp*(1-(1/disp)));

sig2 = 1/alpha;

pie = alpha / (mu + alpha);

do center = 1 to 20;

do over o_sfc;

o_sfc=RAND('NEGBINOMIAL',pie,alpha);

end;

output;

end; *replicate do loop;

run;

proc transpose data=sims (drop=disp mu alpha sig2 pie) out=sims2; by center; run;

proc means data=sims2 n mean var std cv min max; class center;var col1;title'Averages';run;

/***code***/

AXIS1 LABEL=(HEIGHT=1.8 'X-axis label' FONT='ARIAL' JUSTIFY=CENTER)

      ORDER=(1 to 20 by 1)

      VALUE=('Center 1' 'Center 2' 'Center 3' 'Center 4' 'Center 5' 'Center 6' 'Center 7' 'Center 8' 'Center 9' 'Center 10' 'Center 11' 'Center 12'

             'Center 13' 'Center 14' 'Center 15' 'Center 16' 'Center 17' 'Center 18' 'Center 19' 'Center 20' ANGLE=90)

      MAJOR=()

      ;

PROC BOXPLOT DATA=sims2;

    PLOT col1*center / BOXSTYLE=SCHEMATIC

                       HAXIS=AXIS1

                       ;

    INSETGROUP N MEAN (5.1) STDDEV (4.1);

RUN;

Thank you very much,

Lu

SAS Employee
Posts: 967

Re: Display x-axis tick mark values in boxplot

I'm not too familiar with "proc boxplot" (since it's not actually part of the SAS/Graph product), but from my little bit of experience I seem to recall that it doesn't support all of the features of the axis statement ... therefore maybe it doesn't support hardcoding the value text.

But, one work-around would be to use a user-defined format, such as the following (and, of course, there are several different ways to define a user-defined format) ...

AXIS1 LABEL=(HEIGHT=1.8 'X-axis label' FONT='ARIAL' JUSTIFY=CENTER)
      ORDER=(1 to 20 by 1);

proc format;
value myfmt
1 = "Center 1"
2 = "Center 2"
3 = "Center 3"
4 = "Center 4"
5 = "Center 5"
6 = "Center 6"
7 = "Center 7"
8 = "Center 8"
9 = "Center 9"
10 = "Center 10"
11 = "Center 11"
12 = "Center 12"
13 = "Center 13"
14 = "Center 14"
15 = "Center 15"
16 = "Center 16"
17 = "Center 17"
18 = "Center 18"
19 = "Center 19"
20 = "Center 20"
;
run;


PROC BOXPLOT DATA=sims2;
format center myfmt.;
    PLOT col1*center / BOXSTYLE=SCHEMATIC
                       HAXIS=AXIS1
                       ;
    INSETGROUP N MEAN (5.1) STDDEV (4.1);
RUN;

Contributor
Posts: 49

Display x-axis tick mark values in boxplot

Thanks for your answer. But your way still only gives odd centers. And I hope all centers could appear cause in my true data all 20 centers have different names. Any other suggestions? Thank you.

Lu

SAS Employee
Posts: 967

Display x-axis tick mark values in boxplot

Oops - my bad!  I had been running in v9.3 DMS sas, which defaults to "ods graphics on", which is angling the x-axis values by defult (so that they fit).

Angling them manually will probably fix you up!...

AXIS1 LABEL=('X-axis label' JUSTIFY=CENTER) ORDER=(1 to 20 by 1) value=(angle=-45);

Or, here's a complete program that should hard-code everything to come out the way I'm seeing it:

%let name=box001;
filename odsout '.';

data sims;
call streaminit(16812);
array o_sfc osfc1-osfc20;
mu=200;
disp=5;
alpha= mu / (disp*(1-(1/disp)));
sig2 = 1/alpha;
pie = alpha / (mu + alpha);
do center = 1 to 20;
do over o_sfc;
o_sfc=RAND('NEGBINOMIAL',pie,alpha);
end;
output;
end; *replicate do loop;
run;

proc transpose data=sims (drop=disp mu alpha sig2 pie) out=sims2; by center; run;

proc means data=sims2 n mean var std cv min max; class center;var col1;title'Averages';run;

proc format;
value myfmt
1 = "Center 1"
2 = "Center 2"
3 = "Center 3"
4 = "Center 4"
5 = "Center 5"
6 = "Center 6"
7 = "Center 7"
8 = "Center 8"
9 = "Center 9"
10 = "Center 10"
11 = "Center 11"
12 = "Center 12"
13 = "Center 13"
14 = "Center 14"
15 = "Center 15"
16 = "Center 16"
17 = "Center 17"
18 = "Center 18"
19 = "Center 19"
20 = "Center 20"
;
run;

GOPTIONS DEVICE=png;
ODS LISTING CLOSE;
ODS HTML path=odsout body="&name..htm" style=sasweb;

goptions htext=1.8pct ftext='arial';

AXIS1 LABEL=('X-axis label' JUSTIFY=CENTER) ORDER=(1 to 20 by 1) value=(angle=-45);

PROC BOXPLOT DATA=sims2;
format center myfmt.;
    PLOT col1*center / BOXSTYLE=SCHEMATIC
                       HAXIS=AXIS1
                       des='' name="&name";
    INSETGROUP N MEAN (5.1) STDDEV (4.1);
RUN;

quit;
ODS HTML CLOSE;
ODS LISTING;

Contributor
Posts: 49

Display x-axis tick mark values in boxplot

This is exactly what I want. Thank you very much.

Lu

Ask a Question
Discussion stats
  • 4 replies
  • 1489 views
  • 3 likes
  • 2 in conversation