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

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 3 replies
  • 627 views
  • 0 likes
  • 4 in conversation