Hi, I am struggling a bit with the axis labels in my SGPLOT...
Program:
proc sgplot data = my_data;
Vbarbasic X / response=VAR1 name='Series1' fillattrs=(color=orange) legendlabel='LABEL1';
Vbarbasic X / response=VAR2 name='Series2' fillattrs=(color=Purple) legendlabel='LABEL2';
Series x=X y=VAR3 / LINEATTRS=(pattern=solid color=Blue) name='Series1' legendlabel='LABEL3' ;
STEP x=X y=VAR4 / LINEATTRS=(pattern=solid color=Red ) name='Series6' legendlabel='LABEL4' ;
YAXIS label="Production";
XAXIS label ="Moment" values=(0 to 96) VALUESROTATE=diagonal2 valuesformat=MY_FMT.;
keylegend "Series1" "Series2" "Series3" "Series4" "Series5" "Series6"/ title="" location=outside position=right across=1;
run;
The format of the labels looks like: 05-31 00:00, 05-31 01:00, etc.
Labeling all the x-values produces one black bar of unreadable text so I want to label just a subset. Changing the values statement eg to values=(0 to 96 by 4) reduces the number of observations plotted and that is not what I want. So I want all observations plotted in the graph and only a specific subset labeled on the axis
I'm sure I have done this before, but can't find the to do it anymore.
Can somebody help me?
Regards, Arie
You can add the FITPOLICY=ROTATETHIN option to the XAXIS statement to have the procedure rotate the values and thin (remove) some of the tick values.
For example:
XAXIS label ="Moment" values=(0 to 96) VALUESROTATE=diagonal2 valuesformat=MY_FMT. fitpolicy=rotatethin;
I hope that helps.
Marcia
Is variable X numeric or character, according to PROC CONTENTS? The results you are getting make me think it is character. If it is character, then you will need to convert it to an actual numeric date/time value, assuming that you want it to be a date/time value (is that what you want? you tell us what you don't want, but you haven't really been specific about what you do want).
At first it were timestamps but I transformed these to numbers, here from 1 to 96
The labels will display 1 as "05-31 00:00", 2 as "05-31 01:00", etc
Is this variable that goes from 1 to 96 numeric or character, according to PROC CONTENTS?
If it is numeric, what is the format according to PROC CONTENTS?
Variables in Creation Order
# Variable Type Len Format Label
3 X Num 8 ZO_DAN_RIJ.
and that format says:
1="05-31 00:00"
2="05-31 01:0"
etc
You can add the FITPOLICY=ROTATETHIN option to the XAXIS statement to have the procedure rotate the values and thin (remove) some of the tick values.
For example:
XAXIS label ="Moment" values=(0 to 96) VALUESROTATE=diagonal2 valuesformat=MY_FMT. fitpolicy=rotatethin;
I hope that helps.
Marcia
Did you try valuesdisplay= option?
https://blogs.sas.com/content/graphicallyspeaking/2019/04/22/mortgage-rates-overlaying-multiple-year...
For example:
xaxis values=('01jan1960'd to '01jan1961'd by month)
valuesdisplay=('Jan' ' ' 'Mar' ' ' 'May' ' ' 'Jul' 'Aug' 'Sep' 'Oct' 'Nov' 'Dec' ' ');
yes...
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.