BookmarkSubscribeRSS Feed
kuridisanjeev
Quartz | Level 8

Hello All,

 

Is there is any way to assign different colors to each axis (X and Y) separately ?

With below code, color getting assigned for both the axis line. But I need to assign different colors to each axis.

proc template;
define style styles.axis;
parent=styles.htmlblue;
class GraphAxisLines /
contrastcolor=red;
end;
run;

ods html style=axis;

proc sgplot data=sashelp.class;
scatter x=weight y=height;
run;

 

But my requirement is as below :

kuridisanjeev_0-1699604951156.png

Any suggestions greatly appreciated !!

 

Regards,
Sanjeev.K

6 REPLIES 6
Ksharp
Super User

%sganno
data sganno;
 %SGARROW( X1=0, Y1=0,X2=0,Y2=100,DIRECTION= "OUT",X1SPACE="WALLPERCENT",Y2SPACE="WALLPERCENT",
            X2SPACE="WALLPERCENT",Y1SPACE="WALLPERCENT",LINECOLOR="blue" ,SHAPE="BARBED" )
 %SGARROW( X1=0, Y1=0,X2=100,Y2=0,DIRECTION= "OUT",X1SPACE="WALLPERCENT",Y2SPACE="WALLPERCENT",
            X2SPACE="WALLPERCENT",Y1SPACE="WALLPERCENT",LINECOLOR="green" ,SHAPE="BARBED" )
run;


proc sgplot data=sashelp.class noborder sganno=sganno noautolegend ;
scatter x=weight y=height/datalabel=name group=sex;
yaxis  label='Y'  labelpos=top ;
xaxis  label='X'  labelpos=right;
run;

Ksharp_0-1699608194356.png

 

kuridisanjeev
Quartz | Level 8

Thanks @Ksharp ,

 

Is there any we can do this with proc template ?

 

Im using SGRENDER in my program. Apologies for not being clear with in my earlier post.

 

 

Ksharp
Super User
Sorry. I have no idea about it.
Maybe @DanH_sas @tc knew the answer.
tc
Lapis Lazuli | Level 10 tc
Lapis Lazuli | Level 10

Don't know how much of this still holds but check out this 2019 post from @Jay54 re: some GTL limitations as well as some suggested workarounds. I wonder if in your case you could suppress the real axis lines and instead use REFERENCELINEs at x=0 and y=0, which would allow you to specify different COLORs for LINEATTRs. Good luck!

Ksharp
Super User

According to TC , add two refline to mock X Y axis.

 

proc sgplot data=sashelp.class noborder;
scatter x=weight y=height;
refline 50.5/axis=x lineattrs=(thickness=4 color=green);
refline 50/axis=y lineattrs=(thickness=4 color=red);
yaxis offsetmin=0 display=(noline);
xaxis offsetmin=0 display=(noline);
run;

Ksharp_0-1700300142787.png

 

LeRoyBessler
Obsidian | Level 7

The commonest color blindness cannot distinguish red from green. Sanjeev.K actually wanted black and green. (Look for more of my work on communication effective use of color and on Visual Data Insights.)

sas-innovate-wordmark-2025-midnight.png

Register Today!

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.


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
  • 1725 views
  • 5 likes
  • 4 in conversation