Hotel Text

9

hotel_300_5Yesterday, I published an article on Axis values display, where I mentioned the desire expressed by many users to get x-axis tick values in Hotel text orienttion.  The name comes from the way many hotel signs are displayed as shown on the right.  Such arrangement of text can also be very useful for many Asian languages.

There is no direct support for displaying this text in SGPLOT or GTL using some option.  So, I brought up the topic during lunch, and Lingxiao made a great suggestion - We could use the axis values splitting feature to get such arrangement of the x-axis tick values.

If you recall, we can use the FitPolicy=SplitAlways, and this means the value will be split on every occurrence of the split character, which is a space by default.  So, if we can add spaces between each character of the category values and use this FitPolicy, we should get x-axis tick values displayed as hotel text.

dataHere is the code for modifying the names and a view of the data.  First, I find the longest string for name (code not shown below), then I used the prxchange function to replace each character by the same character plus a space.

data class;
length newname $&maxlen;
set sashelp.class;
newname = prxchange('s/(.)/$1 /', -1, name);
run;

Now, we can use this new variable as the category and set FitPolicy=SplitAlways to get Hotel text as shown below right.  This method is very scaleable and can be applied to any use case.  Some details in the code are trimmed to fit.  See linked program below for full details.

barcharthoteltitle 'Height by Name';
proc sgplot data=class noautolegend noborder;
vbar newname / response=height;
xaxis display=(nolabel noline noticks)
fitpolicy=splitalways;
yaxis display=(noline);
run;

SGPLOT code:  hoteltext

Share

About Author

Sanjay Matange

Director, R&D

Sanjay Matange is R&D Director in the Data Visualization Division responsible for the development and support of the ODS Graphics system, including the Graph Template Language (GTL), Statistical Graphics (SG) procedures, ODS Graphics Designer and related software. Sanjay has co-authored a book on SG Procedures with SAS/PRESS.

Related Posts

9 Comments

    • Sanjay Matange
      Sanjay Matange on

      Thanks, Louise and Susan. If you are a GTL user, the code is even more simple and elegant. Just use the eval expression in the BarChart statement directly with the FITPOLICY. No need to generate a new data set.
      barchart category=eval(prxchange('s/(.)/$1 /', -1, name)) response=height;

  1. Bill Droogendyk on

    I'm not liking it! Best practice for data visualization would suggest the use of a horizontal bar chart so that the labels can be easily read. Ditto for the y axis label.

  2. Pingback: Diagonal tick values - Graphically Speaking

Back to Top