Following data has two groups Group 1
and Group 2
. Each group has multiple subjects.
data sgplot_CPA;
input trt_group$ time$ subject$ 11. results;
datalines;
Group-1 1 203-070-001 20
Group-1 3 203-070-001 30
Group-1 7 203-070-001 35
Group-1 10 203-070-001 50
Group-1 14 203-070-001 40
Group-1 21 203-070-001 25
Group-1 28 203-070-001 40
Group-1 US 203-070-001 30
Group-1 1 203-070-003 25
Group-1 3 203-070-003 35
Group-1 7 203-070-003 30
Group-1 10 203-070-003 40
Group-1 14 203-070-003 50
Group-1 21 203-070-003 21
Group-1 28 203-070-003 24
Group-1 US 203-070-003 31
Group-1 1 203-070-005 32
Group-1 3 203-070-005 22
Group-1 7 203-070-005 30
Group-1 10 203-070-005 56
Group-1 14 203-070-005 28
Group-1 21 203-070-005 35
Group-1 28 203-070-005 29
Group-1 US 203-070-005 41
Group-2 1 203-070-007 15
Group-2 3 203-070-007 45
Group-2 7 203-070-007 23
Group-2 10 203-070-007 48
Group-2 14 203-070-007 26
Group-2 21 203-070-007 17
Group-2 28 203-070-007 35
Group-2 US 203-070-007 11
Group-2 1 203-070-008 27
Group-2 3 203-070-008 40
Group-2 7 203-070-008 25
Group-2 10 203-070-008 30
Group-2 14 203-070-008 40
Group-2 21 203-070-008 19
Group-2 28 203-070-008 28
Group-2 US 203-070-008 39
;
run;
I would like to add two legend in the Spaghettin plot, one for Treatment group (trt_group)
and one for subject
. Say for Group-1, All line will be purple color, within each group separate marker for each subject to identify the subject trend.
Here is code I have tried,
proc sgplot data=sgplot_CPA;
styleattrs datacontrastcolors=(purple green orange)
datasymbols=(squarefilled trianglefilled circlefilled StarFilled TriangleDownFilled )
datalinepatterns=(Solid Solid Solid ShortDash ShortDash MediumDash LongDash MediumDashShortDash);
/* title 'Study Results by Treatment Group';*/
series x=time y=results / group=subject grouplc=trt_group name='grouping' groupdisplay=cluster clusterwidth=0.25 Markers MARKERATTRS = (color = black) ;
scatter x =time y = results / group = subject name = 'subjects' groupdisplay=cluster clusterwidth=0.25 markerattrs=(color = black );
keylegend 'grouping' / type=linecolor sortorder = ASCENDING Position = TopLeft title="Treatment";
keylegend 'subjects' / type =marker sortorder = ASCENDING Position = Bottom title="Subject";
xaxis label="Visit";
yaxis label="Result Score";
footnote J=L "US=Unscheduled";
run;
Here is the output
How can I change the highlighted legend to different marker style? For example, 203-070-001 should have star symbol with purple color, 203-070-003 should have square with purple color, and 203-070-005 should have triangle with purple color and similar for Group 2. Any help is appreciated.