brewerpal | Generate Brewer color palette(s) | brewerpal |
The BREWERPAL macro generates a set of SAS/Graph colors for one of the color palettes developed by Cynthia Brewer. These include color scales for sequential (quantitative) variables, discrete (qualitative) variables, and bipolar (diverging) variables, with varying numbers of levels. The intended use is for constructing sets of color values with SAS/Graph, such as in SYMBOL and PATTERN statements.
See: Color Brewer for an online application demonstrating these color scales. See brewer.all for an image with maximal number of colors for each scale.
The result is returned in an output data set with a COLOR variable (RGB color code). Optionally, the list of all colors may be saved to a macro variable as a blank-separated list.
The BREWERPAL macro is modeled on the RColorBrewer R package. See: http://CRAN.R-project.org/package=RColorBrewer
It requires that the data set colors.brewer has already been created (by the file
brewer.sas).
You may have to modify the libname statement in the macro, or specify the LIB=
parameter for something other than 'colors'.
As implemented here, it simply selects observations from the &lib..brewer data set.
The BREWERPAL macro is defined with keyword parameters. Typically, the N=
and PALETTE=
arguments are specified.
The arguments may be listed within parentheses in any order, separated
by commas. For example:
%brewerpal(n=7, palette=Accent);
N=3
]
PALETTE=
is not specified, all palettes are selected.
LIB=COLORS
]
OUT=PALETTE
]
OUT=
data set.
%include macros(brewerpal); *-- or include in an autocall library; *-- Typical usage, for a given palette; %brewerpal(n=6, palette=Blues, result=blues6); %put blues6 = &blues6; title 'Blues palette, n=6 colors'; proc print;Printed Output:
Obs cat palette nc maxc category paldesc colnum color red green blue 1 3 Blues 6 9 seq Blue shades 1 CXEFF3FF 239 243 255 2 3 Blues 6 9 seq Blue shades 2 CXC6DBEF 198 219 239 3 3 Blues 6 9 seq Blue shades 3 CX9ECAE1 158 202 225 4 3 Blues 6 9 seq Blue shades 4 CX6BAED6 107 174 214 5 3 Blues 6 9 seq Blue shades 5 CX3182BD 49 130 189 6 3 Blues 6 9 seq Blue shades 6 CX08519C 8 81 156Log Output:
80 %put blues6 = &blues6; blues6 = CX08519C CX3182BD CX6BAED6 CX9ECAE1 CXC6DBEF CXEFF3FFGenerate PATTERN statements:
*-- Generate pattern statements with the blues6 list; %genpat(n=6, colors=&blues6);Other examples:
%brewerpal(n=9, palette=YlOrRd); title 'Yellow-Orange-Red palette, n=9 colors'; proc print;
*-- All n=4 palettes for diverging colors; %brewerpal(n=4, category=div); title 'Diverging palettes, n=4 colors'; proc print;