BookmarkSubscribeRSS Feed
soomx
Fluorite | Level 6

Hi all,

 

I'm trying to make swimmer plots, as shown in this example: https://blogs.sas.com/content/graphicallyspeaking/2014/06/22/swimmer-plot/

 

 

I have four treatment groups, all which have the same 8 possible values. My code is as follows:

 

data attrmap;
input ID $ value $ 11-21 linecolor $ 24-32 fillcolor $ 34-42;
datalines;
trtcat1 Any immuno blue blue
trtcat1 Any other charcoal charcoal
trtcat1 Chemo orange orange
trtcat1 SRS green green
trtcat1 Targeted purple purple
trtcat1 WBRT black black
trtcat1 cranio gold gold
trtcat1 radio pink pink
trtcat2 Any immuno blue blue
trtcat2 Any other charcoal charcoal
trtcat2 Chemo orange orange
trtcat2 SRS green green
trtcat2 Targeted purple purple
trtcat2 WBRT black black
trtcat2 cranio gold gold
trtcat2 radio pink pink
trtcat3 Any immuno blue blue
trtcat3 Any other charcoal charcoal
trtcat3 Chemo orange orange
trtcat3 SRS green green
trtcat3 Targeted purple purple
trtcat3 WBRT black black
trtcat3 cranio gold gold
trtcat3 radio pink pink
trtcat4 Any immuno blue blue
trtcat4 Any other charcoal charcoal
trtcat4 Chemo orange orange
trtcat4 SRS green green
trtcat4 Targeted purple purple
trtcat4 WBRT black black
trtcat4 cranio gold gold
trtcat4 radio pink pink
;
run;


ods graphics on /height=10in;
footnote J=l h=1 'Each bar represents one subject.';
proc sgplot data = all_therapy dattrmap=attrmap;
highlow y=item low=swim_start high=swim_end /type=bar fill nooutline
lineattrs=(thickness=2) nomissinggroup transparency=0.5;

highlow y=item low=swim_start high=time_trt1/type=bar fill
lineattrs=(thickness=2) nomissinggroup transparency=0.1
name='t1' group=trtcat1 attrid=trtcat1 legendlabel='Treatment1';

highlow y=item low=time_trt1 high=time_trt2/type=bar fill
lineattrs=(thickness=2) nomissinggroup transparency=0.1
name='t2' group=trtcat2 attrid=trtcat2 legendlabel='Treatment2';

highlow y=item low=time_trt2 high=time_trt3/type=bar fill
lineattrs=(thickness=2) nomissinggroup transparency=0.1
name='t3' group=trtcat3 attrid=trtcat3 legendlabel='Treatment3';

highlow y=item low=time_trt3 high=time_trt4/type=bar fill
lineattrs=(thickness=2) nomissinggroup transparency=0.1
name='t4' group=trtcat4 attrid=trtcat4 legendlabel='Treatment4';

xaxis label='Days' values=(0 to 90 by 5) valueshint;
title 'Patient Treatment Patterns';
yaxis display=(noticks novalues noline) label='Patients' min=1;
keylegend 't1' 't2' 't3' 't4'/ noborder location=inside position=bottomright across=1;
run;
ods graphics off;

 

Even though the attrmap dataset has the values and colors all in the same order, the colors do not correspond in my plot.

I would like the colors to stay the same across the four trtcat1-trtcat4 groups, and I thought this code would give me that. However, some values have different colors.

For example, cranio is pink in the legend for t1 and light green in legend for t2. It looks like same values stay consistent (Any immuno), but the others are not.

 

Any ideas what is causing this issue?

 

Thank you!

 

 

3 REPLIES 3
Reeza
Super User

Try setting attrpriority=none on the ods graphics statement. Without code we can actually run though it's hard to test anything for you unless someone recognizes the problem right away. 

 

https://blogs.sas.com/content/graphicallyspeaking/2015/06/28/attributes-priority-for-the-inquiring-m...

 

PS. I'll also move this to the graphics forum.



soomx
Fluorite | Level 6

Thanks for the response. The attrpriority=none statement didn't resolve the issue.

Not sure what other code is needed? 

GraphGuy
Meteorite | Level 14

If you can post some sample that, that will help us try out various solutions.

 

To be coded like the example you referenced (https://blogs.sas.com/content/graphicallyspeaking/files/2014/06/Swimmer_93.txt), you'll need to add nocycleattrs to the proc sgplot line

 

proc sgplot data = all_therapy dattrmap=attrmap nocycleattrs;

 

Also, make sure that all the values in your 'attrmap' dataset are reading in correctly. I assume the way your code is written that your code & datalines is in the correct columns it's looking for(?), but that when you copy-n-pasted it into the comment above it collapsed the spaces(?) Here's a slightly different version of the code that doesn't depend on the datalines being column-delimited, if you need it:

 

data attrmap;
length id $10 value $20 linecolor fillcolor $20;
infile datalines dlm=',';
input ID value linecolor fillcolor;
datalines;
trtcat1,Any immuno,blue,blue
trtcat1,Any other,charcoal,charcoal
trtcat1,Chemo,orange,orange
trtcat1,SRS,green,green
trtcat1,Targeted,purple,purple
trtcat1,WBRT,black,black
trtcat1,cranio,gold,gold
trtcat1,radio,pink,pink
trtcat2,Any immuno,blue,blue
trtcat2,Any other,charcoal,charcoal
trtcat2,Chemo,orange,orange
trtcat2,SRS,green,green
trtcat2,Targeted,purple,purple
trtcat2,WBRT,black,black
trtcat2,cranio,gold,gold
trtcat2,radio,pink,pink
trtcat3,Any immuno,blue,blue
trtcat3,Any other,charcoal,charcoal
trtcat3,Chemo,orange,orange
trtcat3,SRS,green,green
trtcat3,Targeted,purple,purple
trtcat3,WBRT,black,black
trtcat3,cranio,gold,gold
trtcat3,radio,pink,pink
trtcat4,Any immuno,blue,blue
trtcat4,Any other,charcoal,charcoal
trtcat4,Chemo,orange,orange
trtcat4,SRS,green,green
trtcat4,Targeted,purple,purple
trtcat4,WBRT,black,black
trtcat4,cranio,gold,gold
trtcat4,radio,pink,pink
;
run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 942 views
  • 2 likes
  • 3 in conversation