- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
TRTAN indicates which treatment the subject received in the dummy dataset.
Data were requested...data provided.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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/
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I guess this figure is what you want. If it isn't, please provide more information.
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;