Data visualization with SAS programming

Add arrows (pointers) on x-axis

Accepted Solution Solved
Reply
Contributor
Posts: 30
Accepted Solution

Add arrows (pointers) on x-axis

How do I add these RED arrows on the x-axis?  I have my plot ready, except not knowing how to add those pointers.  Any suggestion?

figure-with-arrow.gif

Anna_H


Accepted Solutions
Solution
‎09-18-2013 11:22 AM
SAS Employee
Posts: 963

Re: Add arrows (pointers) on x-axis

If you want to go with a simple sas/graph software font (rather than a smooth/truetype/anti-aliased operating system font), you could use the arrow character (character 'K') from the sas/graph 'marker' font.

style='marker'; text='K';

Here's a list of the sas/graph software fonts:

SAS/GRAPH(R) 9.2: Reference, Second Edition

View solution in original post


All Replies
Regular Contributor
Posts: 239

Re: Add arrows (pointers) on x-axis

That could be done pretty easily with Annotations.  What are you using to create the graph?  GPLOT?

Contributor
Posts: 30

Re: Add arrows (pointers) on x-axis

Yes, gplot with annotation.  Here is what my code looks like. how do I add these rarrows?

Options.....

legend label=none value=(font='swiss' h=9
        tick = 1  j=l "50 mcg C. diff "    
         .........;

axis1 label=(angle=90 font='swiss' h=11 "Antibody Concentration (Neut units/mL)" )
         order=(1 10 100 1000 10000 100000)
         value=(font='swiss' h=10 tick=1 "1"  tick=2 "10" tick=3 "100" tick=4 "1000" tick=5 "10000" tick=6 "100000")
         minor=none offset=(2,0.2) logbase=2 interval=uneven logstyle=expand;

axis2 label=(font='swiss' h=11 j=c 'Time (Days)')
      order= (0 to 240 by 30);
      value=(font='triplex' h=10 tick=1 "Baseline" tick=2 "Day 14" tick=3 "Month 1" tick=4 "Day 37" tick=5 "Month 2" tick=6 "Month 6"
           tick=7 "Day 187" tick=8 "Month 7") w= 1 minor=none offset=(20,20) interval=uneven;

     symbol1  interpol=join value = dot  color=red line=1   h=8;
            ...

proc gplot data=f_final;

   plot mean*xaxi=trt01pn/ legend=legend haxis=axis2 name="&pgmname   " des=""
          vaxis=axis1 noframe;
run;


Regular Contributor
Posts: 239

Re: Add arrows (pointers) on x-axis

Something like this:

data annotateds;
length function $8;
angle=-90;
color='Red';
line=1;
size=1;
style='open';
xsys='2';
ysys='2';
function='move';
x=100;
y=-10;
output;
function='arrow';
y=5;
output;
function='move';
x=300;
y=-10;
output;
function='arrow';
y=5;
output;
function='move';
x=700;
y=-10;
output;
function='arrow';
y=5;
output;
run;

ods preferences;
proc gplot data=sashelp.prdsale annotate=annotateds;
plot actual*predict;
run;
quit;
ods html close;
SAS Employee
Posts: 963

Re: Add arrows (pointers) on x-axis

Since you only need very short arrows, you don't really need to use the move/arrow technique (that would be for drawing long arrows).  In this case you can use the annotate 'label' function, and an arrow character from any font.  Here's an example...

data annotateds;
length function $8;

function='label'; color='Red'; size=4; hsys='3';
style='Wingdings 3'; text='8f'x;
ysys='1'; y=1.5;
xsys='2';
x=100; output;
x=300; output;
x=700; output;
run;

proc gplot data=sashelp.prdsale annotate=annotateds;
plot actual*predict;
run;

foo.png

Contributor
Posts: 30

Re: Add arrows (pointers) on x-axis

I am unable to add this function="label" into my existing annotationds. But I add dummy treatment group (trt=99) into the original data before annotation.  It seems work except it shows in the legend.  How can I get ride of the bottom legend (red arrows) ? 

f_1_test.png

SAS Employee
Posts: 963

Re: Add arrows (pointers) on x-axis

Using annotated arrows is (imho) the best & most direct way to go. Could you give a little more details about the problem you were getting with them?  Were you getting errors?

When you add the arrows by adding a dummy treatment group (ie, plotting fake data obsns), I don't know of a way to suppress that single legend item in the gplot legend. You could perhaps draw a white box over that legend item using annotate ... but if you're going to use annotate then you might as well annotate the arrows instead Smiley Happy

Contributor
Posts: 30

Re: Add arrows (pointers) on x-axis

The bold italic is the added treatment (plot as red arrow).  How do I do it my annotation instead for these "Red Arrow" ?

Thanks!

data f_final;
   .......
  if avisitn=0 then xaxi=xaxi; *avisitn;
  else if xaxi >. then do;
    if trt01pn=1 then xaxi=xaxi;
    if trt01pn=2 then xaxi=xaxi+0.5;
    if trt01pn=3 then xaxi=xaxi+1; ;
    if trt01pn=4 then xaxi=xaxi+1.5;
    if trt01pn=5 then xaxi=xaxi+2;
    if trt01pn=6 then xaxi=xaxi+2.5;
    if trt01pn=7 then xaxi=xaxi+3;
   if trt01pn=8 then xaxi=xaxi;
  end;
run;


data anno;
length function $8 ;
  retain xsys ysys '2';
  set f_final;
  if trt01pn <9;

  if xaxi>0 then do;
  function='move';xsys='2';ysys='2';x=xaxi; y=lclm;size=1; line = 1; output;
  function='draw';xsys='2';ysys='2';x=xaxi; y=uclm;size=1; line = 1; output;
  end;

  function='move'; if xaxi ne . then x=xaxi+0.1; if uclm ne . then y=uclm+0.1; output;
  function='label'; if xaxi ne . then x=xaxi; if uclm ne . then y=uclm+0.3; size=0.5; style = "special"; text=""; ;output;

  if xaxi>0 then do;
%LINE (xaxi-5, lclm, xaxi+5, lclm, black, 1, 1);
%LINE (xaxi-5, uclm, xaxi+5, uclm, black, 1, 1);
end;
run;

SAS Employee
Posts: 963

Re: Add arrows (pointers) on x-axis

It's probably easiest to create the annotate data set for the arrows separately from your other annotate data set, rather than trying to create it all at the same time.  You can combine the 2 annotate data sets into one later, or you can specify 2 different annotate data sets in your gplot ...

For example, if you have anno1 and anno2 data sets, you could combine them:

data anno_combined; set anno1 anno2;

run;

proc gplot data=foo anno=anno_combined;

plot y*x;

run;

Or you could specify them separately:

proc gplot data=foo anno=anno1;

plot y*x / anno=anno2;

run;

Contributor
Posts: 30

Re: Add arrows (pointers) on x-axis

Got annotation working, but warning "font Winding could not be used"..

What other fonts that I can use to create down arrow?

SAS Employee
Posts: 963

Re: Add arrows (pointers) on x-axis

Are you on a PC, and does it have the Wingding font?

What version of SAS are you using? (older versions might not be able to use the OS fonts)

If you're using SAS 9.3 on a Windows PC, the above code should work.

If not, we'll need to know more about your installation...

Solution
‎09-18-2013 11:22 AM
SAS Employee
Posts: 963

Re: Add arrows (pointers) on x-axis

If you want to go with a simple sas/graph software font (rather than a smooth/truetype/anti-aliased operating system font), you could use the arrow character (character 'K') from the sas/graph 'marker' font.

style='marker'; text='K';

Here's a list of the sas/graph software fonts:

SAS/GRAPH(R) 9.2: Reference, Second Edition

Contributor
Posts: 30

Re: Add arrows (pointers) on x-axis

I work on Unix sas 9.1.3.

style='marker'; text='L' works well.

Thank you so much every question answered perfectly!!

Post a Question
Discussion Stats
  • 12 replies
  • 1094 views
  • 0 likes
  • 3 in conversation