Greetings,
I need to find a way to assign a font color to the Y axis ticks, depending on whether or not the Y value is within a predefined list of values.
The template (which works perfectly) that I must modify to achieve what is requested is the following:
proc template;
define statgraph contourplotparm;
begingraph;
entrytitle "&var Ciclo &ciclo";
layout overlay /
yaxisopts=( offsetmin=0.01 offsetmax=0.01 tickvalueattrs=(size=5pt )
linearopts=(tickvaluesequence=(start=1 end=&nvarie
increment=1) viewmin=1 viewmax=&nvarie
tickdisplaylist=(&ylist)))
xaxisopts=( offsetmin=0.01 offsetmax=0.01 tickvalueattrs=(size=6pt)
linearopts=(tickvaluesequence=(start=&mn_edad end=&mx_edad
increment=1) viewmin=&mn_edad viewmax=&mx_edad
tickvaluefitpolicy = rotatealways
/*tickvaluerotation=0*/
tickdisplaylist=(&xlist)))
;
contourplotparm x=edad y=orden z=&var /
contourtype=fill nhint=7
name="Contour" colormodel=&m_cmodel;
continuouslegend "Contour" / title= "&var" ;
referenceline y=10.5 / lineattrs=(thickness=1 color=black pattern=dash);
referenceline y=%sysevalf(&lbm-0.5) / lineattrs=(thickness=1 color=black pattern= dot );
referenceline y=%sysevalf(&ubm+0.5) / lineattrs=(thickness=1 color=black pattern=dot);
referenceline y=%sysevalf(&lba-0.5) / lineattrs=(thickness=1 color=black pattern=dash);
endlayout;
endgraph;
end;
run;
I appreciate your help
There's not an option to allow you to change the attributes for individual tick values. But, you could use an axis table to place values beside the tick marks (suppressing the axis tick values) so that they appear as the tick values. The axis table will allow you to use an attribute map to change the attributes for individual axis table values. To get this to work, you will need to know the tick values that will be used for the axis.
Below is a sample that shows how to do this.
ods path (prepend) work.templat(update); proc template; define statgraph contourplotparm; begingraph; entrytitle "Contour Plot of Height and Weight"; /* Define an attribute map named COLORS to associate the group values 1 and 2 with the desired colors */ discreteattrmap name="colors"; value "1" / textattrs=(color=red); value "2" / textattrs=(color=black); enddiscreteattrmap ; /* associate the attribute map with the GRP group variable */ discreteattrvar attrvar=groupcolors var=grp attrmap="colors"; /* define a lattice layout to place the axis table and plot side by side */ layout lattice / columnweights=preferred columndatarange=union rowdatarange=union columns=2; /* Use the AXISTABLE statement to place the YVALUE variable values associating the values with the GROUPCOLORS attribute map variable */ layout overlay / walldisplay=none xaxisopts=(display=none offsetmin=0 offsetmax=0) yaxisopts=(display=(label) label="Weight"); AxisTable Value=yvalue y=yvalue / labelPosition=min colorGroup=groupcolors Display=(Values); endlayout; /* plot */ layout overlay / xaxisopts=(offsetmin=0 offsetmax=0 linearopts=(thresholdmin=0 thresholdmax=0)) yaxisopts=(display=(line ticks) offsetmin=0 offsetmax=0 /* specify the tick values for the axis */ linearopts=(tickvaluesequence=(start=50 end=250 increment=50) thresholdmin=0 thresholdmax=0)); contourplotparm x=height y=weight z=density / contourtype=fill nhint=12 name="Contour" colormodel=twocolorramp; continuouslegend "Contour" / title="Density"; endlayout; endlayout; endgraph; end; run; /* create plot data defining the YVALUE variable to contain the axis tick values and associating specific values with a group variable, GRP */ data gridded; set sashelp.gridded end=last; if last then do; output; do yvalue=50 to 250 by 50; if yvalue in(100 200) then grp=1; else grp=2; output; end; end; else output; run; /* Create the plot */ proc sgrender data= gridded template=contourplotparm; run;
There's not an option to allow you to change the attributes for individual tick values. But, you could use an axis table to place values beside the tick marks (suppressing the axis tick values) so that they appear as the tick values. The axis table will allow you to use an attribute map to change the attributes for individual axis table values. To get this to work, you will need to know the tick values that will be used for the axis.
Below is a sample that shows how to do this.
ods path (prepend) work.templat(update); proc template; define statgraph contourplotparm; begingraph; entrytitle "Contour Plot of Height and Weight"; /* Define an attribute map named COLORS to associate the group values 1 and 2 with the desired colors */ discreteattrmap name="colors"; value "1" / textattrs=(color=red); value "2" / textattrs=(color=black); enddiscreteattrmap ; /* associate the attribute map with the GRP group variable */ discreteattrvar attrvar=groupcolors var=grp attrmap="colors"; /* define a lattice layout to place the axis table and plot side by side */ layout lattice / columnweights=preferred columndatarange=union rowdatarange=union columns=2; /* Use the AXISTABLE statement to place the YVALUE variable values associating the values with the GROUPCOLORS attribute map variable */ layout overlay / walldisplay=none xaxisopts=(display=none offsetmin=0 offsetmax=0) yaxisopts=(display=(label) label="Weight"); AxisTable Value=yvalue y=yvalue / labelPosition=min colorGroup=groupcolors Display=(Values); endlayout; /* plot */ layout overlay / xaxisopts=(offsetmin=0 offsetmax=0 linearopts=(thresholdmin=0 thresholdmax=0)) yaxisopts=(display=(line ticks) offsetmin=0 offsetmax=0 /* specify the tick values for the axis */ linearopts=(tickvaluesequence=(start=50 end=250 increment=50) thresholdmin=0 thresholdmax=0)); contourplotparm x=height y=weight z=density / contourtype=fill nhint=12 name="Contour" colormodel=twocolorramp; continuouslegend "Contour" / title="Density"; endlayout; endlayout; endgraph; end; run; /* create plot data defining the YVALUE variable to contain the axis tick values and associating specific values with a group variable, GRP */ data gridded; set sashelp.gridded end=last; if last then do; output; do yvalue=50 to 250 by 50; if yvalue in(100 200) then grp=1; else grp=2; output; end; end; else output; run; /* Create the plot */ proc sgrender data= gridded template=contourplotparm; run;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.