Data visualization with SAS programming

Refline in SQ plot, turn labels horizonal

Accepted Solution Solved
Reply
Contributor NWV
Contributor
Posts: 29
Accepted Solution

Refline in SQ plot, turn labels horizonal

Hello, I have code that resembles this:

proc sgplot data=d1;

histogram myvariable/scale=count BINWIDTH=5;

refline 0.3 0.7 1.77 2.78 10/axis=X label=("100%" "82%" "82%" "76%" "37%") LINEATTRS=(color=red);*add the 5 reference lines and labels;

run;

When I run it, it produces the histogram I want, with the reference lines I want.  However, the labels for the reference lines are turned vertically, not horizontal in normal reading fashion.  I could not find any option to turn those labels horizontal.  Is there a way in SAS to do it? Thank you, Nicole


Accepted Solutions
Solution
‎08-20-2015 11:13 AM
SAS Super FREQ
Posts: 1,044

Re: Refline in SQ plot, turn labels horizonal

Yes, the "Insert Image" feature is turned off as it is often used to spam the site.  It is a problem for us all.

Sometimes the issue can be reproduced using one of the SASHELP data sets like Cars or Heart.

proc sgplot data=sashelp.heart;

  histogram cholesterol;

  refline 200 210 220 / axis=x label=("200" "210" "220") labelattrs=(size=12);

  xaxis max=400;

  run;

proc sgplot data=sashelp.heart;

  histogram cholesterol;

  refline 200 210 220 / axis=x label=("200" "210" "220") labelloc=inside labelattrs=(size=12);

  xaxis max=400;

  run;

With LABELLOC=INSIDE, colliding labels will be drawn,but the results may be less then ideal.

View solution in original post


All Replies
SAS Super FREQ
Posts: 1,044

Re: Refline in SQ plot, turn labels horizonal

A picture or runnable program would help to see wht is going on.  The default location for labels is outside.  So, if the reference line labels get too close and collide, they all will be rotated.  You can provide more width, or move them inside.

Contributor NWV
Contributor
Posts: 29

Re: Refline in SQ plot, turn labels horizonal

I would love to attache a picture.  I have a screen shot, saved as a jpg, but when I try and "insert image" to this reply box, it does not work.  I've tried both IE and chrome.  I will try some of your other suggestions, and see if I can get a better result.  The data is not in the public domain, so a runnable program with the same set up would be rather time consuming.  Thank you very much for the response.

Solution
‎08-20-2015 11:13 AM
SAS Super FREQ
Posts: 1,044

Re: Refline in SQ plot, turn labels horizonal

Yes, the "Insert Image" feature is turned off as it is often used to spam the site.  It is a problem for us all.

Sometimes the issue can be reproduced using one of the SASHELP data sets like Cars or Heart.

proc sgplot data=sashelp.heart;

  histogram cholesterol;

  refline 200 210 220 / axis=x label=("200" "210" "220") labelattrs=(size=12);

  xaxis max=400;

  run;

proc sgplot data=sashelp.heart;

  histogram cholesterol;

  refline 200 210 220 / axis=x label=("200" "210" "220") labelloc=inside labelattrs=(size=12);

  xaxis max=400;

  run;

With LABELLOC=INSIDE, colliding labels will be drawn,but the results may be less then ideal.

Contributor NWV
Contributor
Posts: 29

Re: Refline in SQ plot, turn labels horizonal

As you suggest, with the LABELLOC=INSIDE, colliding labels are drawn, but they overlap.  I did try the labelattrs=(size=12), but that option does not appear to work in my refline statement.  Not sure if that is just me, or a base SAS thing.  I am running SAS 9.3 TS Level 1m2 W32_7 Pro platform.  I will revisit the data a decide if some of the reference lines can be dropped.  But thank you very much for the bit about label location, because I never would have guessed that would turn the labels horizontal, into normal reading angle.

SAS Super FREQ
Posts: 1,044

Re: Refline in SQ plot, turn labels horizonal

Technically, LABELLOC does not "turn" the labels to horizontal.  It just draws the label in the normal way, and if they collide, too bad.  The default LABELLOC=OUTSIDE does extra work for you to avoid collision between labels and any potential axis labels too.  If such collision is detected, all labels are turned sideways, or at an angle.

You don;t really need the LABELATTRS=(SIZE=12).  I did that to trigger the collisions.  This option may have been added at SAS 9.40 or later.

If these labels are a must, one possibility is to stagger alternate labels top and bottom using LABELPOS:

proc sgplot data=sashelp.heart;

  histogram cholesterol;

  refline 200 220 / axis=x label=("200" "220") labelloc=inside labelattrs=(size=12);

  refline 210 230 / axis=x label=("210" "230") labelloc=inside labelpos=min labelattrs=(size=12);

  xaxis max=400;

  run;

Contributor NWV
Contributor
Posts: 29

Re: Refline in SQ plot, turn labels horizonal

That is an excellent suggestion, I will try it out.  The author wants the labels on there, no way to get around it!

Post a Question
Discussion Stats
  • 6 replies
  • 453 views
  • 3 likes
  • 2 in conversation