BookmarkSubscribeRSS Feed
lcmichael_unc
Fluorite | Level 6

Hi Folks,

I've created a scatter plot in SGPLOT with the GROUP= option and overlaid it with a regression also with the GROUP= option. Because of the density of the data points in the scatter plot, I want to specify a contrasting colors for the regression lines that are different from the scatter plot marker colors and thus improves readability but I cannot find a way to do this, even with an ATTRID= specification. Adjusting the transparency of the markers for the scatter plot does not help. The overlaid regression lines cannot be the same color. Many thanks for all suggestions. Code below, example attached.

 

data attrmap;
set &library..tablvars_labs_evnts_phz&phz.(keep=CIRRHOSIS);
if CIRRHOSIS='Y' then linecolor='Blue';
else if CIRRHOSIS='N' then linecolor='Red';
id='myid';
run;
proc sort data=&library..tablvars_labs_evnts_phz&phz.; by TESTCD CIRRHOSIS EOTWKS; run;
proc sgplot data=&library..tablvars_labs_evnts_phz&phz. noautolegend;
by TESTCD;
where BINSVR='SVR' and TESTCD in ('PLAT');
styleattrs datacontrastcolors=(salmon bigb green) datasymbols=(plus circle square);
scatter y=NUMRSLT x=EOTWKS / group=CIRRHOSIS splitcharnodrop splitchar='*' markerattrs=(size=8) transparency=0.7;
reg y=NUMRSLT x=EOTWKS / degree=3 group=CIRRHOSIS lineattrs=(thickness=8 pattern=4) attrid=myid;
refline -24 -12 -8 0 12 52 78 104 / axis=x lineattrs=(pattern=shortdash) transparency=0.2
label=("TXST-24wk" "TXST-12wk" "TXST-8wk" "EOT" "SVR" "1 yr. PTX" "1.5 yr. PTX" "2 yr. PTX")
labelattrs=(Color=green Family=Arial Size=8 Weight=Bold) lineattrs=(Color=green thickness=3)
labelpos=auto labelloc=outside ;
xaxis type=linear /*offsetmin=0 offsetmax=0.35 min=-0.5 max=0.5*/
values=(-120 to 180 by 24) minor valueattrs=(Family=Arial Size=10 Weight=bold)
label="WEEKS" labelattrs=(Color=black Family=Arial Size=10 Weight=Bold)
labelpos=datacenter;
* format TESTCD $lbtst.;
label MEANDIFF="MEAN DIFFERENCE" LCL="Lower 95%CL" UCL="Upper 95%CL" NOBSUSED='NOBS' NUMRSLT='PLATELET MEASURMENT' DYSPSTEOT='WEEKS FOLLOWING EOT';
yaxis type=linear valueattrs=(Family=Arial Size=11 Weight=bold) labelpos=top
fitpolicy=splitalways splitchar='*'
values=(0 to 800 by 100)
valueattrs=(Family=Arial Size=10 Weight=bold)
label="MEASURMENT" labelattrs=(Color=black Family=Arial Size=10 Weight=Bold) labelpos=datacenter;
keylegend / title="GROUP" titleattrs=(Color=black Family=Arial Size=10 Weight=Bold) across=2 location=outside valueattrs=(Color=black Family=Arial Size=10 Weight=Bold);
run;

 

1 REPLY 1
Norman21
Lapis Lazuli | Level 10

It is difficult to read your code to see if you have already done this, but you can set group attributes in the SGPLOT procedure syntax, as described here:

 

https://blogs.sas.com/content/graphicallyspeaking/2013/07/14/setting-graph-colors-is-easier-with-sas...

 

For future reference, it is helpful to post SAS code using the "Insert SAS Code" button at the top of the message body.

Norman.
SAS 9.4 (TS1M6) X64_10PRO WIN 10.0.17763 Workstation

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 1 reply
  • 1761 views
  • 0 likes
  • 2 in conversation