BookmarkSubscribeRSS Feed
Esterina
Obsidian | Level 7

Hi All,

 

I have a proc sgplot vector and the labelplacement makes my label textsize is smaller than I would like them to be. I know the labelplacement is trying to make the labels not overlapped, but I also don't want them to be smaller. Is there a way to have it like I have specified them to be on the datalabelattrs=(size=23pt family="Calibri")?

 

Thanks,

Esterina

6 REPLIES 6
ballardw
Super User

As a minimum it would be a good idea to show the code for the graph you are making so we can see the options you are currently using. Copy the text from your editor and then on the forum open a text or code box by clicking on the </> or "running man" icon above the message window.

Better would be to include a copy of the current graph you have so we can see what you talking about.

 

Since there is no option "labelplacement" that I am aware of I am going to guess that you are referring to the text that labels the tick marks on the axis. The options to directly control the text of the tick mark labels is the VALUEATTRS option of an XAXIS or YAXIS statement to override text font, size and color. You may also want to look at VALUESROTATE = DIAGONAL or VERTICAL to change the orientation of the text if is long enough that changing the font size is not enough to make things fit.

Esterina
Obsidian | Level 7

Ah sorry, this is my code:

labelplacement is an automatic placement on the ods graphic, the default is greedy, so I usually don't specify this.

So this labelplacement will cause the textsize smaller, even though we have specified the textsize explicitly on the code.

 

proc sgplot data=prep_graph_&t_i._comb sganno=anno noautolegend noopaque nowall noborder pad=&t_pad. dattrmap=prep_color;
	vector y=y_y1 x=x_y1/ 
		datalabel=t_label datalabelattrs=(size=&t_text_size_pt.pt family="&global_font.") 
		xorigin=x_y2 yorigin=y_y2 ARROWHEADSHAPE=filled LINEATTRS=(color='white' pattern=dot);
	scatter y=y_y1 x=x_y1/ 
		markerattrs=(symbol=squarefilled size=7px)
		group=dot_color_group attrid=dot_color_group
		;
	xaxis 
		values=(&min_x. to &max_x. by &by_x.)
		label="  "
		labelattrs=(size=&t_text_size_pt.pt color=&gc_text. family="&global_font.")
		valueattrs=(size=19pt color=&gc_text. family="&global_font.")
		offsetmin=&t_offset_h_min.
		offsetmax=&t_offset_h_max.
		;
	yaxis 
		values=(&min_y. to &max_y. by &by_y.)
		label="  " 
		labelattrs=(size=&t_text_size_pt.pt color=&gc_text. family="&global_font.") 
		valueattrs=(size=19pt color=&gc_text. family="&global_font.")
		offsetmin=&t_offset_v_min.
		offsetmax=&t_offset_v_max.
		;
	title height=1pt color=&gc_text. font="&global_font." "  ";
	format y_y1 percent8. x_y1 comma8.;
run; 

 

DanH_sas
SAS Super FREQ

You might want to try the NOSCALE option on the ODS GRAPHICS statement:

ods graphics / noscale;

 

Let us know if that works.

Esterina
Obsidian | Level 7

Thank you @DanH_sas ! I have used noscale, but it still makes the label text smaller, here is my ods graphics:

ods graphics on / 
	reset 
	noscale
	noborder
	imagename="g1_&&t_segment1c_&t_i.._&&t_segment2c_&t_i..&grf_nm." 
	outputfmt=gif 
	height=&t_ypixels. width=&t_xpixels. 
	scalemarkers=on scale=off; 
DanH_sas
SAS Super FREQ

After further checking, it turns out you cannot currently turn off the autosizing that is sometimes applied by the collision avoidance algorithms. However, there are a couple of workarounds for your situation. I'm not sure which would work best for you, as I have not seen you graph to know the density of points and labels.

  1. Specify a position for the data labels -- if you specify a position for the data labels, then the size will be maintained. However, you might get some collisions, based on the point density.
  2. Use a TEXT plot to do the labeling and use a column to specify the positions -- This will require more work, but it will give you the control to position each label anywhere around the point you want. On the TEXT statement, the POSITION option can take a literal value or a variable containing the valid position values. I would start by giving all points the same position value in the data. Then, adjust the ones that have a collision.

Hope this helps!

Esterina
Obsidian | Level 7

Thanks @DanH_sas ! Unfortunately both are not really better than what we have right now. I have used annotation right now to show the labels, however it will take a lot of trial and error to fix the labels if they are overlapped. This is another question, I saw there is an article written by Warren F. Kuhfeld about a macro labelit, using proc plot, ods output the labels and then proc reg and adjustments. Do you happen to know a way to output the label position from proc sgplot? Is there such thing? Thanks!

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1073 views
  • 2 likes
  • 3 in conversation