BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
hsaul
Calcite | Level 5

I am attempting to create a patient profile plot with four panels using PROC SGPANEL. The fourth panel consists of a series plot with two groups and I would like each of the two curves to be labeled. I am using the CURVELABEL option to accomplish this, but it appears that the labels overlap when the baseline values are similar. Any suggestions on how to stagger these labels? My code and output are below. Thank you in advanced!

 

title "Safety and Efficacy Profile for Subject 10001";
proc sgpanel data=test nocycleattrs dattrmap=attrmap;;
	panelby id / onepanel layout=rowlattice uniscale=column novarname spacing=10;
	refline 0 / axis=x lineattrs=(thickness=1 color=black);
	highlow y=mhdecod low=stdy high=endy / type=bar barwidth=0.8 lowlabel=mhlabel lowcap=lowcap highcap=highcap fillattrs=(color=CX003DF5);
	highlow y=acmdecod low=stdy high=endy / type=bar barwidth=0.8 lowlabel=cmlabel lowcap=lowcap highcap=highcap fillattrs=(color=CXED7D31);
	highlow y=aedecod low=stdy high=endy / type=bar group=severity labelattrs=(color=black) lineattrs=(color=black pattern=solid) barwidth=0.8 lowlabel=aelabel highcap=highcap attrid=Severity;
	series x=stdy y=aval / group=param attrid=Outcome curvelabel curvelabelpos=start curvelabelattrs=(color=black) lineattrs=(pattern=solid);
	rowaxis display=(nolabel noticks novalues) min=0;
	colaxis grid label='                                                 Study Day' offsetmin=0.3 values=(-28 to 210 by 7) fitpolicy=thin;
run;

 

SGPanel1.png 

1 ACCEPTED SOLUTION

Accepted Solutions
Jay54
Meteorite | Level 14

Curve labels do not have collision avoidance.  However, data labels do.  One work around would be to display datalabels on your series plot only for the first or last point by creating a label variable that has the curve value only for the first or last point.  The labels should avoid collision.  If the labels are not too close, the will be put in the upper right position.

 

Simple sample code:

data stocks;
  set sashelp.stocks(where=(date > '01Jan2004'd));
  if date = '01Dec05'd then label=stock;
run;

proc sgplot data=stocks;
  series x=date y=close / group=stock datalabel=label;
run;

 

View solution in original post

7 REPLIES 7
PGStats
Opal | Level 21

Even if you stagger the curve labels, it won't be obvious which curve they are associated with. There would be room for curvelabelpos=end, which would better identify your curves.

PG
hsaul
Calcite | Level 5

Thanks for your feedback! Unfortunately, since I am generating this for multiple subjects, the data could go either way and the overlap is just as likely to occur at the end as the beginning.

 

2018-08-06_10-44-34.jpg

 

If there is a solution for staggering, I thought I might be able to color code the labels to match the curves so that they could be easily identifiable. Open to any other suggestions though!

ballardw
Super User

If your data is likely to be close often enough then perhaps you should not be excluding that bit from the legend.

JeffMeyers
Barite | Level 11

You have so much white space to the left of this graph, would you be able to just fit a KEYLEGEND for this plot into there alone?

Jay54
Meteorite | Level 14

Curve labels do not have collision avoidance.  However, data labels do.  One work around would be to display datalabels on your series plot only for the first or last point by creating a label variable that has the curve value only for the first or last point.  The labels should avoid collision.  If the labels are not too close, the will be put in the upper right position.

 

Simple sample code:

data stocks;
  set sashelp.stocks(where=(date > '01Jan2004'd));
  if date = '01Dec05'd then label=stock;
run;

proc sgplot data=stocks;
  series x=date y=close / group=stock datalabel=label;
run;

 

hsaul
Calcite | Level 5

Sanjay - This is very helpful and an elegant workaround! Thanks very much!

 

2018-08-07_17-55-03.jpg

Jay54
Meteorite | Level 14

Good to know it works.  Now, if you want better control on the position of the labels, you could instead overlay a TEXT plot with the same idea.  However, now you can set a position column in the data for each label, one as TOPLEFT, one as BOTTOMLEFT.  Now, you can get the two clean labels on the left, one above, one below without collision.  However, note this idea may work only for your specific 2 label case with coincident starting point.

    text x=x y=y text=label / position=position;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 2916 views
  • 3 likes
  • 5 in conversation