Graphics Programming

Data visualization using SAS programming, including ODS Graphics and SAS/GRAPH. Charts, plots, maps, and more!
BookmarkSubscribeRSS Feed
_Hopper
Obsidian | Level 7

I'm trying to make something like a swimmer plot, but some of the arrows go in the negative direction. HighLow cannot be used this way correct? What are my options? In this case I have a baseline score and sometimes the score declines so the arrow will point in the negative direction while most are positive.

 

Y-axis variable = Subject Identifier

X-axis variable = 2 score columns one with the baseline value and one with the value at the target timepoint.

 

As a further wrinkle, I would like to place a reference line between groups of subjects on the y-axis.

6 REPLIES 6
ballardw
Super User

Data is helpful if you want working code.

 

A Vector plot should work.

The x=value and y=subject values are the coordinates of the end of the plot. Add Xorigin (base), yorigin the same as y.

Probably use Arrowdirection=out to have a point at the ending value.

_Hopper
Obsidian | Level 7

Data:

 

Subjid TRTAN BASE AVAL

A1            1            12         14

A2            1            10        8

B1           2            11          11

B2           2           10          13

 

I would like to have a divider between treatment groups on the y-axis if it's possible to do.

 

ballardw
Super User

What role does TRTAN play? Nothing was mentioned in the original post about this.

Vector plots require numeric values. So this creates a value of the line number, then create a custom format to display the text of the subjid original value. That numeric requirement may make it much easier to place useful reference lines, maybe not. You didn't provide a description of how to separate the values so I made a guess. Refline can use variables in the data set for the line  location value and label text if you want many reference lines. So it might be that adding some additional variables would be useful.

 

You might use the TRTAN variable as a GROUP variable to indicate membership in a group, if that is the purpose, instead of a separation line.

 

data have;
   input Subjid $ TRTAN $ BASE AVAL;
   yval=_n_;
datalines;
A1            1            12         14
A2            1            10        8
B1           2            11          11
B2           2           10          13
;

proc format library=work;
value yval
1='A1' 
2='A2' 
3='B1' 
4='B2'
;
run;


proc sgplot data=have;
   vector x=aval y=yval / xorigin=base yorigin=yval 
          arrowdirection=out  lineattrs=(thickness=10)
   ;
   format yval yval.;
   refline 2.5 / axis=y  label='Some text label';
   yaxis label='Subject' values=(1 to 4);
   label aval='Some description';
run;
_Hopper
Obsidian | Level 7

TRTAN indicates which treatment the subject received in the dummy dataset.

Data were requested...data provided.

Ksharp
Super User

https://blogs.sas.com/content/graphicallyspeaking/2014/06/22/swimmer-plot/

https://blogs.sas.com/content/graphicallyspeaking/2018/05/13/a-combined-waterfall-and-swimmer-plot/

https://blogs.sas.com/content/graphicallyspeaking/2018/11/16/waterfall-graph-with-more-data-for-subj...

And better post a picture to illustate what you are looking for.

Don't let me to guess what you want.

 

And you can switch these two values manually from low to high to show the right output.

data have;
input Subjid $ TRTAN BASE AVAL;
cards;
A1            1            12         14
A2            1            8        10
B1           2            11          11
B2           2           10          13
;

proc sgplot data=have;
highlow y=Subjid low=base high=aval/type=bar group=trtan;
refline 'A2'/discreteoffset=0.5;
run;

Ksharp_0-1726536335456.png

 

Eric_Lee
Fluorite | Level 6

I guess this figure is what you want. If it isn't, please provide more information.

screenshot.png

 

The code is as follows:

data have;
input subjid $ trtan base aval;
cards;
A1 1 12 14
A2 1 8 10
A3 1 12 9
B1 2 11 11
B2 2 10 13
B3 2 14 10
;
run;

data have_new;
  length subjid $200 trtan base_new aval_new 8 base aval 8;
  length highcap lowcap $200;
  set have;
  if base>aval then do;
    highcap='NONE';
    lowcap='FILLEDARROW';
    base_new=aval;
    aval_new=base;
  end;
  else do;
    highcap='FILLEDARROW';
    lowcap='NONE';
    base_new=base;
    aval_new=aval;
  end;
run;



proc template;
define statgraph highlowbar;
  begingraph;
    layout overlay /
      xaxisopts=(display=(line ticks tickvalues) griddisplay=on
        linearopts=(viewmin=0 viewmax=15))
      yaxisopts=(griddisplay=on display=(line ticks tickvalues));

      highlowplot y=SUBJID high=AVAL_NEW low=BASE_NEW /
        group=drug outlineattrs=(pattern=solid)
        type=bar barwidth=0.4 highcap=HIGHCAP lowcap=LOWCAP;
    endlayout;
  endgraph;
end;

ods graphics on / reset outputfmt=png imagename='highlowbar';

proc sgrender data=have_new template=highlowbar;
run;

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1564 views
  • 2 likes
  • 4 in conversation