Hi all,
I'm trying to find the posibility to create a scatter plot graph with many labels that can be adjusted manually. I know that using SAS Graph Template Language we can create a scatter plot with auto adjustment on the labels, and I'm quite pleased with this, but just in case if the labels are still too closed and overlapped I would have the capability to adjust it manually too. Is it possible to do this? I heard activeX graph will be deprecated and ODS Graphics Editor too.
Thank you in advance!
Here is the sample graph
I'm not sure where the final destination is for your graph, but here is one way to do it. First, generate your output using the ODS WORD destination. Here is an example:
ods _all_ close;
ods word file="class.docx";
ods graphics / outputfmt=svg;
proc sgplot data=sashelp.class;
scatter x=weight y=height / datalabel=name;
run;
ods _all_ close;
Next, open the file in Microsoft Word. Right-click on the graph and select, "Convert to Shape". You can then edit and move your labels. Then, deselect the graph, right-click on it, and select, "Save as Picture". This image will external save your edits as a PNG image.
Hope this helps!
Try datalabel= option, that would avoid to overlap the two closed label .
proc sgplot data=sashelp.class;
scatter x=weight y=height/group=sex datalabel=name;
run;
As you can see there is no overlapped label , sas just do it for you .
Thanks! I know this one, but I'm looking a way to make it interactive, that we can adjust the labels manually by drag and drop.
On the ODS GRAPHICS statement, there is an option called LABELPOSITION that contains two fitting algorithms: GREEDY and SA (simulated annealing). The default is GREEDY, which works pretty well. However, if you have cases where GREEDY does not produce what you want, try SA. The graph might take a little longer to produce, but it might give you better results in some dense cases.
Thanks Dan! that's good to know. But I'm looking a way to make it interactive that I can adjust the labels manually after that by drag and drop.
I'm not sure where the final destination is for your graph, but here is one way to do it. First, generate your output using the ODS WORD destination. Here is an example:
ods _all_ close;
ods word file="class.docx";
ods graphics / outputfmt=svg;
proc sgplot data=sashelp.class;
scatter x=weight y=height / datalabel=name;
run;
ods _all_ close;
Next, open the file in Microsoft Word. Right-click on the graph and select, "Convert to Shape". You can then edit and move your labels. Then, deselect the graph, right-click on it, and select, "Save as Picture". This image will external save your edits as a PNG image.
Hope this helps!
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.