BookmarkSubscribeRSS Feed
aquaman20
Calcite | Level 5

Hi SAS users,

 

Unfortunately my label references from my refline in PROC sgplot are vertical and I would like to rotate them 45 degrees to the right. Is there a solution or a command for this?

12 REPLIES 12
PeterClemmensen
Tourmaline | Level 20

Can you show us your code please? What version of SAS do you use?

aquaman20
Calcite | Level 5

Here is the Code and I use SAS 9.4:

proc sgplot data=test2;

 

histogram T1 / scale=percent binwidth=0.25 fillattrs=(color='#C5AE45' ) legendlabel= "Vehicle group (VG)";
histogram T2 / scale=percent binwidth=0.25 fillattrs=(color='#216771' ) legendlabel = "Dose group (DG)" ;


refline 0.309 / axis = x LINEATTRS= (color='#C5AE45' PATTERN=dash thickness=2)label="Geom. mean";
refline 0.575/ axis = x LINEATTRS= (color='#C5AE45' PATTERN=shortdashdot thickness=2)label="Median";
refline 1.592 / axis = x LINEATTRS= (color='#C5AE45' PATTERN=solid thickness=2)label="Arithm. mean;

refline 15.653 / axis = x LINEATTRS= (color='#216771' PATTERN=dash thickness=2)label="Geom. mean" transparency=0.5;
refline 13.599 / axis = x LINEATTRS= (color='#216771' PATTERN=shortdashdot thickness=2)label="Median" transparency=0.5 ;
refline 18.879 / axis = x LINEATTRS= (color='#216771' PATTERN=solid thickness=2)label="Arithm. mean" transparency=0.5 ;
run;

PeterClemmensen
Tourmaline | Level 20

I'm not sure, but I don't think its possible to rotate 45 degrees. The only simple, non GTL workaround I can think of is to create another refline in the same position as the on already there with a transparent label like below. 

 

proc sgplot data=sashelp.class;
   scatter x=height y=weight;
   refline 62 / axis=x LINEATTRS= (color='#C5AE45' PATTERN=dash thickness=2) label="Geom. mean";
   refline 62 / axis=x LINEATTRS= (color='#C5AE45' PATTERN=dash thickness=2) label="xxxxxxxxxx" labelattrs=(color="white");
run;

 

This will rotate your refline label by 90 degrees. Let me know if it works for you 🙂

aquaman20
Calcite | Level 5

Sorry, also does´t work really well, because now the label overlay each other and you can´t read anything.

 

PeterClemmensen
Tourmaline | Level 20

What do you mean by overlay each other? can you post an image?

PeterClemmensen
Tourmaline | Level 20

Can you post an image of your entire plot please?

aquaman20
Calcite | Level 5

Sorry, I can´t .Unfortunately, the data are confusing.

PeterClemmensen
Tourmaline | Level 20

Ok. I can't see your data, so I can't help you on that one. My best advice is to use the mentioned workaround and place the 'fake' refline statements before any of the 'real' ones. Remember to specify the same color for the refline labels as the background. That way, the 'real' refline labels will overwrite the 'fake' ones and that shouldn't be a problem.

 

I hope you find a suitable solution 🙂 Otherwise, don't hesitate to ask again.

ballardw
Super User

@aquaman20 wrote:

Here is the Code and I use SAS 9.4:

proc sgplot data=test2;

 

histogram T1 / scale=percent binwidth=0.25 fillattrs=(color='#C5AE45' ) legendlabel= "Vehicle group (VG)";
histogram T2 / scale=percent binwidth=0.25 fillattrs=(color='#216771' ) legendlabel = "Dose group (DG)" ;


refline 0.309 / axis = x LINEATTRS= (color='#C5AE45' PATTERN=dash thickness=2)label="Geom. mean";
refline 0.575/ axis = x LINEATTRS= (color='#C5AE45' PATTERN=shortdashdot thickness=2)label="Median";
refline 1.592 / axis = x LINEATTRS= (color='#C5AE45' PATTERN=solid thickness=2)label="Arithm. mean;

refline 15.653 / axis = x LINEATTRS= (color='#216771' PATTERN=dash thickness=2)label="Geom. mean" transparency=0.5;
refline 13.599 / axis = x LINEATTRS= (color='#216771' PATTERN=shortdashdot thickness=2)label="Median" transparency=0.5 ;
refline 18.879 / axis = x LINEATTRS= (color='#216771' PATTERN=solid thickness=2)label="Arithm. mean" transparency=0.5 ;
run;


Try this. For the offending REFLINE do not add a label.

To you data add an observation with a text variable holding the label text, and an x and y coordinate. Plot that variable using a TEXT plot. You can use options such as ROTATE for the text value and TEXTATTRS to control color, font and size.

Jagadishkatam
Amethyst | Level 16

you may try the below option in xaxis statement

 

xaxis ValuesRotate=Diagonal;
Thanks,
Jag
aquaman20
Calcite | Level 5

Sorry doesn´t work. Thanks for your help.

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 12 replies
  • 1655 views
  • 0 likes
  • 4 in conversation