Here us an example of a proc sgplot that I have been using to draw figures of a spline analysis.
How do I change the colour in the shaded band area between the confidence intervals , and how can I specify exact color choices?
How do I even get rid of edges so I don't have an X2 and Y2 axis?
proc sgplot data = QuadSBPVp ;
Title "Severe Vasolegia up to 24h by Induction SBP";
band x=Ind_SBP1 lower=l upper=u;
YAXIS label = "Estimated probably of Severe Vasoplegia in 1st 24 hours";
series x = Ind_SBP1 y = fit/ curvelabel = "Predicted value" lineattrs=(color= Blue pattern=dash);;
series x = Ind_SBP1 y = u/ curvelabel = "95% Upper CI" lineattrs= (color=purple pattern=dash);
series x = Ind_SBP1 y = l/ curvelabel = "95% Lower CI"lineattrs = (color = yellow pattern = solid thickness =5);
run;
Besides standard colours, how to I specify an exact colour, eg:
Colour 1 (blue): c100 m57 y0 k2
Colour 2 (green): c71 m26 y100 k25
Colour 3 (Pink): c10 m70 y0 k0
Colour 4 (gold): c0 m50 y100 k0
Colour 5 (light blue): c80 m0 y0 k0
Colour 6 (orange): c0 m80 y100 k0
I need to get these colours exactly right for the journal
You're partly correct and you also need leading zeros.
/* Colour 1 (blue)
CMYK= c100 m57 y0 k2
RGB= 0,107,250
Hex=006bfa
*/
%* allows you to convert colours WIHTOUT having to look it up online or through
another tool;
%COLORMAC;
data _null_;
put "%RGB2HLS(CXE7B3B4)";
run;
data _null_;
r = 0;
g = 107;
b = 250;
rgb="CX" || put(r,hex2.) || put(g,hex2.) || put(b,hex2.);
put rgb;
run;
proc sgplot data=sashelp.class;
scatter x=Height y=Weight /
markerattrs = (COLOR=CMYK99570002
symbol=CircleFilled
size =12);
run;
proc sgplot data=sashelp.class;
scatter x=Height y=Weight /
markerattrs = (COLOR=CX006bfa
symbol=CircleFilled
size =12);
run;
Color-Naming Scheme
|
Example
|
---|---|
RGB
|
COLOR=(CX98FB98) |
CMYK
|
COLOR=(FF00FF00) COLOR=(CMYK00FFFF00) |
HLS
|
COLOR=(H14055FF) |
HSV
|
COLOR=(V0F055FF) |
Gray Scale
|
COLOR=(GRAY4F) |
SAS Registry Colors
|
COLOR=(palegreen) |
CNS Color Names
|
COLOR=(VeryLightPurplishBlue) |
Having a strange time with setting the colours......
I've read and sort-of understood all the links you have sent to me.
Previously I was able to set the right colours by translating the CMYK settings to RGB or Hex.
Doesnt seem to be working anymore as Im no longer getting the desired colours.
proc sgplot data = SplineOut;
YAXIS label = "Estimated probably of Vasoplegia within 24h in ICU";
XAXIS label = "Induction SBP";
band x=Ind_SBP1 lower=l upper=u/fillattrs = (color = ########## );
series x = Ind_SBP1 y = fit/ curvelabel = "Predicted value" lineattrs=(color =black pattern=solid);
series x = Ind_SBP1 y = u/ curvelabel = "Upper CI" lineattrs=(color =black pattern=LONGDASHSHORTDASH);
series x = Ind_SBP1 y = l/ curvelabel = "Lower CI" lineattrs=(color =black pattern=LONGDASHSHORTDASH);
run;
/* Colour 1 (blue): c100 m57 y0 k2 RGB= 0 107 250 Hex=006bfa*/
/* Colour 2 (green): c71 m26 y100 k25 RGB= 55 142 0 Hex=378e00*/
/* Colour 3 (Pink): c10 m70 y0 k0 RGB= 230 77 255 Hex=e64dff*/
/* Colour 4 (gold): c0 m50 y100 k0 RGB= 255 128 0 Hex=ff8000*/
/* Colour 5 (light blue): c80 m0 y0 k0 RGB= 51 255 55 Hex=33ffff*/
/* Colour 6 (orange): c0 m80 y100 k0 RGB= 255 51 0 Hex=ff3300*/
Any takers?
I just tried one of Rick's Macros:
https://blogs.sas.com/content/iml/2012/10/22/whats-in-a-name.html
Seems to work, although the data A "Rose" step didn't seem to be necessary.
This is what I did:
/* convert integer 0--255 to 2 digit hex 00-FF */
%macro hex2(n);
%local digits n1 n2;
%let digits = 0123456789ABCDEF;
%let n1 = %substr(&digits, &n / 16 + 1, 1);
%let n2 = %substr(&digits, &n - &n / 16 * 16 + 1, 1);
&n1&n2
%mend hex2;
/* convert RGB triplet (r,g,b) to SAS color in hexadecimal.
The r, g, and b parameters are integers in the range 0--255 */
%macro RGB(r,g,b);
%cmpres(CX%hex2(&r)%hex2(&g)%hex2(&b))
%mend RGB;
proc sgplot data=sashelp.class;
scatter x=height y=weight / markerattrs=(size=14 symbol=CircleFilled
color=%RGB(0,107,250) );
run;
proc sgplot data = SplineOut;
YAXIS label = "Estimated probably of Vasoplegia within 24h in ICU";
XAXIS label = "Induction SBP";
band x=Ind_SBP1 lower=l upper=u/fillattrs = (color =%RGB(0,107,250));
series x = Ind_SBP1 y = fit/ curvelabel = "Predicted value" lineattrs=(color =black pattern=solid);
series x = Ind_SBP1 y = u/ curvelabel = "Upper CI" lineattrs=(color =black pattern=LONGDASHSHORTDASH);
series x = Ind_SBP1 y = l/ curvelabel = "Lower CI" lineattrs=(color =black pattern=LONGDASHSHORTDASH);
run;
I don't know why a Macro was necessary because this macro was meant I guess to pre-set a value for Rose.
Is it not possible in SAS do achieve these colours with out the macro for the RGB settings?
Why can I not get this by specifying the CMYK setting for the desired colour?
And Yes, despite 20 years living in the States, I still can't spell proper-like.
@ChristosK wrote:
Why can I not get this by specifying the CMYK setting for the desired colour?
And Yes, despite 20 years living in the States, I still can't spell proper-like.
You can, the blog post you're referencing is 5 years old, so thats what you needed to do 5 years ago. SAS has changed in 5 years.
I'd indicated above how you specify the colour specifications for the various different notations with the link to the current documentation but here's a fully reproducible example. The colour is from Colorbrewer and is the Orange scheme with the darkest colour.
proc sgplot data=sashelp.cars;
scatter x=mpg_city y=mpg_highway / markerattrs=(COLOR=CMYK1065950);
run;
PS. Help us help you by posting programs we can run. https://stackoverflow.com/help/mcve
Well then something is obviously missing, and it must be something very simple.
The CMYK codes I have are correct as I have checked these palettes across a variety of websites .
When I apply these to anything in proc sgplot using CMYK or RGB codes or hex codes, the colours are just wrong.
I'm using SAS University edition on a browser, not SAS base. Could this have something to do with it?
Nope, that's what I'm using as well. In fact, it's the latest SAS version so its less likely to be that.
Post your code, preferably using SASHELP.CLASS so we can run it and explain what isn't working.
Here is an example.
I just used the numeric code that was (presumably) given as the CMYK code.
Here is the web page with the instructions to authors. https://academic.oup.com/bja/pages/Instructions_To_Authors
Having said that, I just spoke with the Editor. Since they just changed the publisher we are no longer necessarily required to use these colours but I don't like loose ends. Would very much like to understand what is happening here.
You're partly correct and you also need leading zeros.
/* Colour 1 (blue)
CMYK= c100 m57 y0 k2
RGB= 0,107,250
Hex=006bfa
*/
%* allows you to convert colours WIHTOUT having to look it up online or through
another tool;
%COLORMAC;
data _null_;
put "%RGB2HLS(CXE7B3B4)";
run;
data _null_;
r = 0;
g = 107;
b = 250;
rgb="CX" || put(r,hex2.) || put(g,hex2.) || put(b,hex2.);
put rgb;
run;
proc sgplot data=sashelp.class;
scatter x=Height y=Weight /
markerattrs = (COLOR=CMYK99570002
symbol=CircleFilled
size =12);
run;
proc sgplot data=sashelp.class;
scatter x=Height y=Weight /
markerattrs = (COLOR=CX006bfa
symbol=CircleFilled
size =12);
run;
Fascinating.
Not sure I am getting the same result running the macro as you are. I was looking at this the last couple of nights as well.
CMYK99570002 does not produce the same colour as CX006bfa. The Blue colour is much lighter in the former, although its good that you are conforming that we cannot place a value of 100 with current options in SAS.
I thought the Hex code of 006bfa was another colour coding system separate from RGB. If all we need to do is place CX in front of the hex code (that being the code for RGB), then the problem is solved. So the
0,107,250 is not the RGB code after all?
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.