Data visualization with SAS programming

Add colours to graph // proc template + proc sgrender

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 11
Accepted Solution

Add colours to graph // proc template + proc sgrender

[ Edited ]

Dear all,

 

I would like to add colors to my regression plot. I plotted the regression of proportion of protein consumed in the morning with total amount of protein consumed. What I would like to do is give observations belonging to males and females different colours. Does someone have suggestions where I must add this information in my syntax (see below).


Many thanks in advance.

 

proc template;

define statgraph propprotbytotprot;

begingraph;

entrytitle "Proportion of protein ingested during morning by total protein ingested";

layout overlay /xaxisopts=(griddisplay=on)yaxisopts=(griddisplay=on);

modelband "cli" / name="mb1" legendlabel="95% Predict" datatransparency=0.5;

modelband "clm" / name="mb2" legendlabel="95% Mean";

regressionplot x=prop_sum_prot y=prot_day / cli="cli" clm="clm";

scatterplot x=prop_sum_prot y=prot_day;

discretelegend "mb1" "mb2" / border=true across=1 valign=bottom halign=right location=inside;

entry halign=left " Nobs=" eval(strip(put(n(prot_day),12.0))) / valign=top;

endlayout;

endgraph;

end;

run;

proc sgrender data=final.hour template=propprotbytotprot ;

label prop_sum_prot="Proportion of protein ingested during morning hours (g)";

label prot_day="Total protein (g)";

run;


Accepted Solutions
Solution
‎12-08-2016 10:41 AM
SAS Super FREQ
Posts: 3,234

Re: Add colours to graph // proc template + proc sgrender

If you want to use different marker attributes for markers in the scatter plot, add

GROUP=sex 

to the SCATTERPLOT statement, where 'sex' is the name of a categorical variable (might be 'gender'...)

 

The colors/symbols that appear are determined by the current style for the ODS destination.  If you don't like the style choice, you can use a different style or define a discrete attribute map that overrides the style.

View solution in original post


All Replies
Solution
‎12-08-2016 10:41 AM
SAS Super FREQ
Posts: 3,234

Re: Add colours to graph // proc template + proc sgrender

If you want to use different marker attributes for markers in the scatter plot, add

GROUP=sex 

to the SCATTERPLOT statement, where 'sex' is the name of a categorical variable (might be 'gender'...)

 

The colors/symbols that appear are determined by the current style for the ODS destination.  If you don't like the style choice, you can use a different style or define a discrete attribute map that overrides the style.

Occasional Contributor
Posts: 11

Re: Add colours to graph // proc template + proc sgrender

Hi Rick,

 

Thank you so much for your fast response. I tried this before, but instead of adding group=sex behind the scatterplot statement, I added it behind the regression statement. This did not work out well (obviously!).

Post a Question
Discussion Stats
  • 2 replies
  • 93 views
  • 0 likes
  • 2 in conversation