Hello all,
I have a relatively simple dataset, with 3 variables: SubjectID, Method1, Method2, where Method1 and Method2 are continuous.
I wish to plot something similar to the Bland-Altman plot, only that my agreement limits will be calculated in somewhat a different way. However the plot should be similar and should look roughly like this:
Assuming that I have calculated the mean (red line) and two limits (blue lines), I can either merge them into to the data or store them into macro variables using SQL or other way.
My question is however about the graph. In the x-axis I will put the mean of Method1 and Method2, and in the y-axis the diff between Method2 and Method1. I have 60 subjects, with repeated measurements for each, giving a total of thousands of data points. I am not sure how to make this graph clear. I thouhgt, for each subject, to plot all his/her points in a different combination of color and marker.
I wanted to ask you how do I tell SAS to create a unique combination ? How do I put a legend below the graph, in a way that doesn't disturb? Does anyone has a better idea how to plot this graph?
I wish to use sgplots, to get the best quality plot I can, is it correct that I need to use refline once to create all 3 lines ?
Thank you in advance !
Okay, here is an example. This one does plot the legend too, however in this case the legend is only 1 character. It's better to plot without the legend, and only label certain subjects if needed.
To add in the error bars just requires two more scatter statements.
data test;
do i = 1 to 60;
subject = i;
m1 = rand("normal", 20, 2);
m2 = m1 + rand("uniform");
output;
end;
run;
proc sgplot data = test;
refline 10 30 / axis = y lineattrs = (color = red pattern = 2); * Reference line of limits;
refline 20 / axis = y lineattrs = (color = blue); * Mean reference line;
scatter x = m1 y = m2 / group = subject;
yaxis min = 0 max = 40; * yaxis range;
run;
Hello, just wondering how many plots do you want to have? Is it 1 or 60?
If it is one, then you can use the group option in sgplot to give you the unique combination of colors and markers? Although some may be repeated. Having a legend of 60 subjects will probably take up to much space though, so you could leave out the legend, and only label certain points (i.e. outliers). What version of SAS do you have please? Have you got an example dataset?
One one? We have to plot grouped data with multiple timepoints, but I wouldn't put it all in one graph, just an example, but 60*10=600, thats going to be very crowded on a normal plot. I would suggest looking at grouping by certain criteria, maybe subjects in the same treatment arm for comparison purposes (sorry, don't know your data so can't give a related example). You could also produce a summarised overall table, mean/min/max say for each subject and just plot the 60 points.
To get you started, there are many examples of graphs for all kinds of purpose given here:
http://blogs.sas.com/content/graphicallyspeaking/
Okay, here is an example. This one does plot the legend too, however in this case the legend is only 1 character. It's better to plot without the legend, and only label certain subjects if needed.
To add in the error bars just requires two more scatter statements.
data test;
do i = 1 to 60;
subject = i;
m1 = rand("normal", 20, 2);
m2 = m1 + rand("uniform");
output;
end;
run;
proc sgplot data = test;
refline 10 30 / axis = y lineattrs = (color = red pattern = 2); * Reference line of limits;
refline 20 / axis = y lineattrs = (color = blue); * Mean reference line;
scatter x = m1 y = m2 / group = subject;
yaxis min = 0 max = 40; * yaxis range;
run;
All the markers are circles? That shouldn't be the case. It should cycle through the colours and the markers. Are all the markers the same colour too? Please check you have not got this option: markerattrs = (symbol = circle)
If your only plotting one subject but have different timepoints, in that case or markers will be the same.
Also I believe you are plotting subjects and time because you're doing repeated measures? In that case you could use time as the symbol and subject as the colour. You will need a different solution to achieve this though. Let me know if this is what you're after?
Okay, the default is that the markers and symbols will change for each distinct value in the group statement. If you have a lot of groups though, there is a chance that the markers and symbols can be repeated. Does the plot show you what you expect?
If you are using HTML destination the style is HTMLBlue, which is a "Color Priority" style. This means only color will change for the first 12 groups, while using same (first) symbol and pattern from the group style elements. Then, at group 13, the symbol and pattern will change to the 2nd in the style, and all the colors will be cycled again.
If you want colors, Symbols and Patterns to change per group, use a style with ATTRPRIORITY=NONE like LISTING. Or, add this option on the ODS Graphics statement.
You can create another macro variable that is rounded to what you want, and then afterwards you can use the label statement in refline to show the formatted value.
The macro variable can be rounded to the number of decimal places you want by using the picture format.
There could be a quicker way to do this, but this way works too.
Here is an example.
data test;
do i = 1 to 60;
do j= 1 to 2;
subject = i;
m1 = rand("normal", 20, 2);
m2 = m1 + rand("uniform");
output;
end;
end;
run;
* Creating picture format;
proc format;
picture reffmt (round)
0-9 = 9.999
10-99 = 99.999
100-999 = 999.9999
1000-9999 = 9999.999
10000-99999 = 99999.999;
run;
%let refline1 = 20.52135467;
%let refline1fmt = %sysfunc(putn(&refline1, reffmt.));
proc sgplot data = test;
refline 10 30 / axis = y lineattrs = (color = red pattern = 2); * Reference line of limits;
refline &refline1. / axis = y lineattrs = (color = blue) label="&refline1fmt."; * Mean reference line;
scatter x = m1 y = m2 / group = subject;
yaxis min = 0 max = 40; * yaxis range;
run;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.