I am creating a plot with both the series and scatter statements. The x-axis is a time variable and the y are numeric values. The final timepoint can occur at different times for each subject. For the scatter plot, I would like the final value to be larger and darker than the others. Is there a way to do this?
The data are in a long format, with one record for each time point per subject, and there are five subjects in each of four groups. The variable "sample" is what indicates whether or not the value is the final value (1 or 2 being the final, while 0 is all other times).
proc sgplot data=sasdata.plots;
styleattrs datacontrastcolors=(red green black blue) datalinepatterns=(solid shortdash mediumdash longdash);
series x=day y=var / grouplc=group_id group=subject_id lineattrs=(pattern=solid) tip=(animal_id group_id) transparency=.4;
scatter x=day y=var / group=group_id markerattrs=(symbol=circlefilled size=5) transparency=.4;
series x=day y=var_mean / group=group_id grouplc=group_id lineattrs=(thickness=3) name="mean";
xaxis values=(-7 0 3 6 9 12 15 18 21 24 28);
where sample in (0,1,2);
keylegend "mean" / type=linecolor title='';
title 'Group Means and Individual Lines, All Samples';
run;
Thank you!
The color change is a problem because all of your colors are already bound to group_id. However, you might be able to change the size using an attrmap. Try my code below (untested) and see if that gets you any closer to what you want.
Hope this helps!
Dan
data myattrmap;
retain id "myid";
input value $ markersize;
cards;
0 5
1 9
2 9
;
run;
proc sgplot data=sasdata.plots dattrmap=myattrmap;
styleattrs datacontrastcolors=(red green black blue) datalinepatterns=(solid shortdash mediumdash longdash);
series x=day y=var / markers groupmc=group_id groupms=sample msattrid=myid grouplc=group_id
group=subject_id lineattrs=(pattern=solid) tip=(animal_id group_id) transparency=.4;
series x=day y=var_mean / group=group_id grouplc=group_id lineattrs=(thickness=3) name="mean";
xaxis values=(-7 0 3 6 9 12 15 18 21 24 28);
where sample in (0,1,2);
keylegend "mean" / type=linecolor title='';
title 'Group Means and Individual Lines, All Samples';
run;
I was thinking about my response on my way home from work, and I realized I had made a mistake -- GROUPMS is for marker SYMBOL, not marker SIZE. Therefore you can change the marker shape at the end, but not its size. The ATTRMAP needs to change to use MARKERSYMBOL instead of MARKERSIZE. Again, untested, the code would look something like the following:
data myattrmap;
retain id "myid";
length marker symbol $ 14;
input value $ markersymbol $;
cards;
0 circlefilled
1 trianglefilled
2 trianglefilled
;
run;
proc sgplot data=sasdata.plots dattrmap=myattrmap;
styleattrs datacontrastcolors=(red green black blue) datalinepatterns=(solid shortdash mediumdash longdash);
series x=day y=var / markers groupmc=group_id groupms=sample msattrid=myid grouplc=group_id
group=subject_id lineattrs=(pattern=solid) tip=(animal_id group_id) transparency=.4;
series x=day y=var_mean / group=group_id grouplc=group_id lineattrs=(thickness=3) name="mean";
xaxis values=(-7 0 3 6 9 12 15 18 21 24 28);
where sample in (0,1,2);
keylegend "mean" / type=linecolor title='';
title 'Group Means and Individual Lines, All Samples';
run;
Thanks, Dan. This code worked to change the symbols for the values I needed. The difference wasn't quite as visible as I had hoped. I ended up using a bubble statement (with the bubble size in a new variable, sampsize) instead to show the difference in sizes, which made the difference much more noticeable.
bubble x=day y=var size=sampsize / group=group_id BRADIUSMAX=5 BRADIUSMIN=2 COLORMODEL=(red green black blue) COLORRESPONSE=group_id nooutline;
Or in your data preparation and another Y value variable only for the last time point and use another scatter statement.
Then plot with different symbol size option and denser transparency setting. 0 might be better but I don't have your data to test with.
scatter x=day y=othvar / group=group_id markerattrs=(symbol=circlefilled size=7) transparency=0.1;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.