BookmarkSubscribeRSS Feed
andypandy_swe
Obsidian | Level 7

I'm trying to create a horizontal barchart with a label above the y-axis values (left aligned) and also a label above the bars (left aligned). 

andypandy_swe_0-1620800443182.png

 

In a simple GTL  barchart I can get the "unit" label but couldn't get the "Some measurement" label above the bars (only at the bottom of the bars) so i figured I'd try and put the y-axis values and the "unit" label in an axistable. So I created a layout lattice with two layout overlays in it, one for the axistable (showing values and label) and one for the barchart (showing only the label). However as seen above the two labels won't align. The label for the axistable is higher than the label for the barchart.

 

So my question is:

Is it possible to get the x-axis label on top of the bars aligned with the y-axis label (and skip the axistable) or

keep the axistable and somehow align not only the axistable/barchart values but also the labels?

 

The template needs to accomodate diffrent number of bars (and thereby different graph heights) so using drawtext isn't really an option (as far as I can see)..

3 REPLIES 3
ballardw
Super User

A quick and dirty try might be to add a referenceline with datatransparency set to completely transparent (doesn't show) and use the curvelabel options to control appearance and location. You would need to provide an axis value for the transparent line.

Jay54
Meteorite | Level 14

The labels should line up vertically. I suggest you report it to SAS Tech Support as a defect.

Aside from that, you could creatively use the BARCHART with TEXTPLOT statement to do this. The data will include an extra text column with the value "Some measurement" for an additional category value of "Unit". The data set has to be judiciously created or merged. You could likely also do this using SGPLOT with VBARPARM and TEXT. I will try it to see if this works using dummy data.

 

Since @DanH_sas provided a good solution, I will skip further work on this.

DanH_sas
SAS Super FREQ

Here is a little example that demonstrates one way to do it:

ods graphics / width=640px height=200px;

data test;
length cat $ 9;
input cat $ resp;
cards;
category1 50
category2 30
category3 70
;
run;

data label;
function="text";
drawspace="wallpercent";
x1=0;
y1=100;
anchor="bottomleft";
label="Some Measurement";
width=40;
output;
run;

proc sgplot data=test sganno=label;
yaxis display=none;
xaxis display=(nolabel);
hbarparm category=cat response=resp;
yaxistable cat / position=left labeljustify=left;
run;

Hope this helps!

Dan

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 1021 views
  • 0 likes
  • 4 in conversation