BookmarkSubscribeRSS Feed
nsamanta
Fluorite | Level 6

PP_Cytof.png

Hello, 

 

I wish to switch the sequence of my tick values on my x-axis. For some reason the logic in my code has shifted the labels for each box plot. for e,g, 'No-Diabetes' is actually equal to 'T1DM' is actually 'T2DM'. However, the data is represented okay. Below is my complicated code-

 

data cytofpercent_scatter ;
set cytofpercent ;
Diagnosis_n = ifn(Diagnosis = 'T1DM', 1, ifn(Diagnosis = 'T2DM', 2, 3));
if Diagnosis="T1DM" then T1DM=-1+0.1*rannor(0);
if Diagnosis="T2DM" then T2DM=1.5+0.1*rannor(0);
if Diagnosis="No-Diabetes" then NoDiabetes=4+0.1*rannor(0);
run;

 

proc format;
value Diagnosis
1 = 'T1DM'
2 = 'T2DM'
3 = 'No-Diabetes'
;
run;

 

proc sort data=cytofpercent ;
by Donor;
run;

proc template;
define statgraph cytof.scatter;
begingraph;
entryTitle "PP CELL DISTRIBUTION";
layout overlay / x2axisopts=(display=none)

xaxisopts=(display=(tickvalues) linearopts=(tickValuelist=(2 1 3) tickvalueformat=Diagnosis.)) 
yaxisopts= (label= "PP Cell Percentage (%)" labelattrs=(weight=bold))
walldisplay=none ;
boxplot x=Diagnosis y=PP_cells_percentage / display=(caps mean median)
fillattrs=(color=white)
meanattrs=(color=Black symbol=diamondFilled) ;

scatterplot x=T1DM y=PP_cells_percentage / xaxis=x2 markerattrs=(color=blue symbol=circleFilled) ;
scatterplot x=T2DM y=PP_cells_percentage / xaxis=x2 markerattrs=(color=red symbol=circleFilled);
scatterplot x=NoDiabetes y=PP_cells_percentage / xaxis=x2 markerattrs=(color=green symbol=circleFilled);
endlayout;
endgraph;
end;
run;

ods listing style=listing;
proc sgrender data=cytofpercent_scatter
template="cytof.scatter";
run;

5 REPLIES 5
pink_poodle
Barite | Level 11

If T2DM and T1DM are switched, it could be because of the tickValuelist= option:

 

proc template;
...

 

*** the order of tick value list is T2DM (2), T1DM (1), No-Diabetes (3);
xaxisopts=(display=(tickvalues) linearopts=(tickValuelist=(2 1 3) tickvalueformat=Diagnosis.)) 
yaxisopts= (label= "PP Cell Percentage (%)" labelattrs=(weight=bold))
walldisplay=none ;
boxplot x=Diagnosis y=PP_cells_percentage / display=(caps mean median)
fillattrs=(color=white)
meanattrs=(color=Black symbol=diamondFilled) ;

 

*** the order of scatterplot statements and color symbols is T1DM, T2DM, No-Diabetes;

scatterplot x=T1DM y=PP_cells_percentage / xaxis=x2 markerattrs=(color=blue symbol=circleFilled) ;
scatterplot x=T2DM y=PP_cells_percentage / xaxis=x2 markerattrs=(color=red symbol=circleFilled);
scatterplot x=NoDiabetes y=PP_cells_percentage / xaxis=x2 markerattrs=(color=green symbol=circleFilled);


endlayout;
endgraph;
end;
run;

nsamanta
Fluorite | Level 6

Hello Pink_Poodle!

 

Thank you so much for your response. 

 

I have actually tried with tickValuelist=(1 2 3) option as well. With that, the position of T1DM and T2DM box-plot changes, but the data represented then becomes correct. I tried something new- Look for the color code. I created new dummy variables to convert my x-axis dummy variables to numeric variable. I have a feeling the issue could be in the dataset? 

 

Organized_cytof.png

 

 

data cytofpercent_scatter ;
set cytofpercent ;
if Diagnosis ='T1DM' then T1DM= 2 ;
If Diagnosis ='T2DM' then T2DM= 1 ;
else if Diagnosis ='No-Diabetes' then NoDiabetes=3 ;
run ;

 

/* Convert numeric values back to categories for axis display */
proc format;
value Diagnosis
2 = 'T1DM'
1 = 'T2DM'
3 = 'No-Diabetes'
;


run;

proc sort data=cytofpercent_scatter ;
by Donor;
run;

 

proc template;
define statgraph cytof.overlay;
begingraph;
entryTitle "PP CELL DISTRIBUTION";
layout overlay / x2axisopts=(display=none)


xaxisopts=(display=(tickvalues) linearopts=(tickvaluelist=(1 2 3) tickvalueformat=Diagnosis.)) 
yaxisopts= (label= "PP Cell Percentage (%)" labelattrs=(weight=bold))
walldisplay=none ;
boxplot x=Diagnosis y=PP_cells_percentage / display=(caps median mean connect)
connect=median
connectattrs=(color=Black pattern=4)
fillattrs=(color=white)
meanattrs=(color=Black symbol=diamondFilled) ;

scatterplot x=eval(0.08*rannor(57)+T1DM) y=PP_cells_percentage / xaxis=x2 markerattrs=(color=blue symbol=circleFilled) ;
scatterplot x=eval(0.08*rannor(57)+T2DM) y=PP_cells_percentage / xaxis=x2 markerattrs=(color=red symbol=circleFilled);
scatterplot x=eval(0.08*rannor(57)+NoDiabetes) y=PP_cells_percentage / xaxis=x2 markerattrs=(color=green symbol=circleFilled);
endlayout;
endgraph;
end;
run;

ods listing style=listing;
proc sgrender data=cytofpercent_scatter
template="cytof.overlay";
run;

 

 

pink_poodle
Barite | Level 11

Hi nsamanta,

This is a very nice code. One interesting thing I found out is that a tick value list does no have to be numeric. That could eliminate the format step:

 

http://support.sas.com/documentation/cdl/en/grstatgraph/65377/HTML/default/viewer.htm#p1iii02qgue4et...

nsamanta
Fluorite | Level 6

Thank you! 

 

I will try this option again then. I kept reading everywhere that it has to be a Numeric value. 

Also is there a plotting option where I can just show the scatter/Jitter for each x-axis group and the Median line? i.e. no boxplot in the background? 

 

best, 

 

 

pink_poodle
Barite | Level 11

You are right, tick value list can only be numeric:

http://support.sas.com/documentation/cdl/en/grstatgraph/65377/HTML/default/viewer.htm#p1iii02qgue4et...

The question about boxes would require modification of the box plot statement. Here are the options for that:

 http://support.sas.com/documentation/cdl/en/grstatgraph/65377/HTML/default/viewer.htm#p1v78jvcpcsd1y...

It could be possible to conceal the boxes by using the box width option with boxwidth = 0.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 5 replies
  • 2364 views
  • 1 like
  • 2 in conversation