## plot by treatment and color different types

Solved
Occasional Contributor
Posts: 12

# plot by treatment and color different types

Hello All, Could you do me a great favor to plot the graph as follows?(plot each TRT separately and set different color for each type) Thanks in advance.

data one;
input TRT X Y Ref type \$;
datalines;
1 1 2 . A
1 2 4 . A
1 3 5 . A
1 4 3 3 A
1 5 2 . A
1 6 4 . A
1 7 6 . A
1 8 2 . B
1 9 2 . B
1 10 5 7 A
2 1 1 . A
2 2 6 2 A
2 3 5 . A
2 4 1 . B
2 5 1 . B
2 6 5 . A
2 7 6 . A
2 8 3 5 A
2 9 2 . A
2 10 4 . A
;
run;

output should be:

Accepted Solutions
Solution
‎02-16-2017 09:01 AM
SAS Employee
Posts: 995

## Re: plot by treatment and color different types

Or, if you are more familiar with Proc Gplot, rather than Proc SGplot, here's another way ...

data anno_reflines; set one (where=(ref^=.));
xsys='1'; ysys='2'; hsys='3'; when='a';
x=0; y=ref; function='move'; output;
x=100; y=ref; function='draw'; color='orange'; size=.1; output;
run;

data one; set one;
if type='B' then y_red=y;
run;

goptions gunit=pct htitle=2.5 htext=2.5 ftitle='albany amt' ftext='albany amt';

symbol1 value=dot color=black height=4pct interpol=join ci=black;
symbol2 value=dot color=red height=6pct interpol=none;

axis1 order=(0 to 10 by 1) minor=none label=(font='albany amt/bold');
axis2 minor=none label=(font='albany amt/bold');

options nobyline;
title1 h=3 justify=left ls=1.5 "TRT=#byval(trt)";
title2 h=3 justify=left ls=0.8 " Plot of Y by X";

proc gplot data=one;
by trt;
plot y*x=1 y_red*x=2 / overlay
vaxis=axis1 haxis=axis2 anno=anno_reflines;
run;

All Replies
PROC Star
Posts: 7,874

## Re: plot by treatment and color different types

Take a look at Robert Allison's page (http://robslink.com/SAS/Home.htm ). He provides code for doing most graphs in SAS.

HTH,

Art, CEO, AnalystFinder.com

SAS Super FREQ
Posts: 1,009

## Re: plot by treatment and color different types

The code is below. To adjust the marker sizes, adjust them in the attrmap. To remove the legend, add NOAUTOLEGEND to the PROC SGPLOT statement.

Hope this helps!

Dan

``````data one;
input TRT X Y Ref type \$;
datalines;
1 1 2 . A
1 2 4 . A
1 3 5 . A
1 4 3 3 A
1 5 2 . A
1 6 4 . A
1 7 6 . A
1 8 2 . B
1 9 2 . B
1 10 5 7 A
2 1 1 . A
2 2 6 2 A
2 3 5 . A
2 4 1 . B
2 5 1 . B
2 6 5 . A
2 7 6 . A
2 8 3 5 A
2 9 2 . A
2 10 4 . A
;
run;

data attrmap;
retain id "myid" markersymbol "circlefilled";
length markercolor \$ 5;
input value \$ markercolor \$ markersize;
cards;
A red   11
B black 7
;
run;

Title "Plot of Y by X";
proc sgplot data=one dattrmap=attrmap;
by TRT;
series x=x y=x / lineattrs=(color=black);
scatter x=x y=x / group=type attrid=myid;
refline Ref / lineattrs=(color=orange);
run;
``````
Solution
‎02-16-2017 09:01 AM
SAS Employee
Posts: 995

## Re: plot by treatment and color different types

Or, if you are more familiar with Proc Gplot, rather than Proc SGplot, here's another way ...

data anno_reflines; set one (where=(ref^=.));
xsys='1'; ysys='2'; hsys='3'; when='a';
x=0; y=ref; function='move'; output;
x=100; y=ref; function='draw'; color='orange'; size=.1; output;
run;

data one; set one;
if type='B' then y_red=y;
run;

goptions gunit=pct htitle=2.5 htext=2.5 ftitle='albany amt' ftext='albany amt';

symbol1 value=dot color=black height=4pct interpol=join ci=black;
symbol2 value=dot color=red height=6pct interpol=none;

axis1 order=(0 to 10 by 1) minor=none label=(font='albany amt/bold');
axis2 minor=none label=(font='albany amt/bold');

options nobyline;
title1 h=3 justify=left ls=1.5 "TRT=#byval(trt)";
title2 h=3 justify=left ls=0.8 " Plot of Y by X";

proc gplot data=one;
by trt;
plot y*x=1 y_red*x=2 / overlay
vaxis=axis1 haxis=axis2 anno=anno_reflines;
run;

☑ This topic is solved.

Discussion stats
• 3 replies
• 187 views
• 2 likes
• 4 in conversation