Stata palettes

Palettes s2, s1, s1r, economist, and mono contain colors used for p1 to p15 in official Stata's schemes files. The palettes look as follows:

. colorpalette, lcolor(black): s2 / s1 / s1r / economist / mono
colors/stata.svg
[top]

Other palettes

Palettes cblind, plottig, 538, mrc, tfl, burd, and lean provide colors found in various user-contributed scheme files. The palettes look as follows:

. colorpalette, lcolor(black): cblind / plottig / 538 / mrc / tfl / burd / lean
colors/other.svg
[top]

Color generators

Evenly spaced HCL hues

The hue palette has been modeled after function hue_pal() from R's scales package by Hadley Wickham. Use options n() (number of colors), hue() (range of hues), chroma(), and luminance() to determine how the colors are generated. Example:

. colorpalette hue, hue(0 -120) chroma(50) luminance(70)
colors/hue0.svg

The following example illustrates how the colors change depending on n():

. local palettes

. forvalues n = 1/10 {
  2.     local palettes `palettes' hue, n(`n') name(n=`n') /
  3. }

. colorpalette, lcolor(black): `palettes'
Code
colors/hue.svg

Note that hue with default options produces the same colors as HCL intense.

[top]

HCL color generator

The HCL palette is a HCL color generator (Hue-Chroma-Luminance; cylindrical representation of CIE L*u*v*). The implementation is based on R's colorspace package. Also see hclwizard.org. Three types of color schemes – qualitative, sequential, and diverging – are supported. See the help file of colorpalette for details on how the colors are computed. For each type a number of presets are provided. Use options hue(), chroma(), luminance(), and power() to modify the presets. Analogous color generators in the LCh space (cylindrical representation of CIE L*a*b*), and the CIECAM02-based J'M'h space are available as LCh and JMh, respectively.

The HCL presets look as follows:

. colorpalette, title("Qualitative") lc(black) n(10): ///
>     HCL qualitative / HCL intense / HCL dark / HCL light / HCL pastel
Code
colors/hcl.svg
. local palettes

. foreach scheme in blues greens grays oranges purples reds heat heat2 ///
>     terrain terrain2 viridis plasma redblue {
  2.     local palettes `palettes' HCL `scheme' /
  3. }

. colorpalette, title("Sequential") gropts(ysize(5.5) scale(.73)): `palettes'
Code
colors/hclseq.svg
. local palettes

. foreach scheme in bluered bluered2 bluered3 greenorange browngreen ///
>     pinkgreen purplegreen {
  2.     local palettes `palettes' HCL `scheme' /
  3. }

. colorpalette, title("Diverging"): `palettes'
Code
colors/hcldiv.svg
[top]

HSV color generator

The HSV palette is similar to the HCL palette, but the colors are generated in the HSV color space (Hue-Saturation-Value). See the help file of colorpalette for details. The presets look as follows:

. colorpalette, title("Qualitative") lc(black) n(10): ///
>     HSV qualitative / HSV intense / HSV dark / HSV light / ///
>     HSV pastel / HSV rainbow
Code
colors/hsv.svg
. local palettes

. foreach scheme in blues greens grays oranges purples reds heat terrain {
  2.     local palettes `palettes' HSV `scheme' /
  3. }

. colorpalette, title("Sequential"): `palettes'
Code
colors/hsvseq.svg
. local palettes

. foreach scheme in bluered bluered2 bluered3 greenorange browngreen ///
>     pinkgreen purplegreen {
  2.     local palettes `palettes' HSV `scheme' /
  3. }

. colorpalette, title("Diverging"): `palettes'
Code
colors/hsvdiv.svg
[top]

Color interpolation

A powerful color generator is also provided via the ipolate() option. The procedure is to select a start color and an end color, and perhaps some intermediate colors, and then apply interpolation to generate a color scale. Several suboptions to select the interpolation space, to set the positions of the origin colors, or to affect the shape of the transition between the colors are available; see the help file of colorpalette for details. Some examples are as follow:

. colorpalette: #fafa6e #2a4858, ipolate(10)      name(Jab) ///
>             / #fafa6e #2a4858, ipolate(10, JMh) name(JMh)
Code
colors/ipolate1.svg
. colorpalette: #fafa6e #2a4858, ipolate(30, HCL power(1.5)) name(slow) ///
>             / #fafa6e #2a4858, ipolate(30, HCL)            name(even) ///
>             / #fafa6e #2a4858, ipolate(30, HCL power(0.7)) name(fast)
Code
colors/ipolate2.svg
. colorpalette: Black Crimson Gold, ipolate(30, pos(0 .3 1)) name(left)   ///
>             / Black Crimson Gold, ipolate(30)              name(middle) ///
>             / Black Crimson Gold, ipolate(30, pos(0 .7 1)) name(right)
Code
colors/ipolate3.svg
[top]

Collections

ColorBrewer

The ColorBrewer collection is a set of color schemes developed by Cynthia Brewer and provided at colorbrewer2.org. The colors are licensed under Apache License Version 2.0 (see copyright note). The color schemes look as follows:

. colorpalette, title("ColorBrewer qualitative") lcolor(black): ///
>     Accent / Dark2 / Paired / Pastel1 / Pastel2 / Set1 / Set2 / Set3
Code
colors/qualitative.svg
. colorpalette, title("ColorBrewer sequential (single hue)"): ///
>     Blues / Greens / Greys / Oranges / Purples / Reds
Code
colors/seq1.svg
. colorpalette, title("ColorBrewer sequential (multi-hue)"): ///
>     BuGn / BuPu / GnBu / OrRd / PuBu / PuBuGn / PuRd / RdPu ///
>     / YlGn / YlGnBu / YlOrBr / YlOrRd
Code
colors/seq2.svg
. colorpalette, title("ColorBrewer diverging"): ///
>     BrBG / PRGn / PiYG / PuOr / RdBu / RdGy / RdYlBu / RdYlGn / Spectral
Code
colors/diverging.svg

For the sequential and diverging schemes, the colors depend on the size of the palette. For example, here are the 5-color versions of the diverging schemes:

. colorpalette, title("ColorBrewer diverging") n(5): ///
>     BrBG / PRGn / PiYG / PuOr / RdBu / RdGy / RdYlBu / RdYlGn / Spectral
Code
colors/diverging5.svg
[top]

Viridis and friends

The viridis collection provides perceptually uniform colormaps from matplotlib, a Python 2D plotting library. The colormaps are as follows:

. colorpalette: viridis / plasma / inferno / magma / cividis  ///
>     / twilight / twilight shifted
Code
colors/viridis.svg
[top]

Other matplotlib maps

The matplotlib palette provides several other colormaps from matplotlib:

. local palettes

. foreach scheme in jet autumn spring summer winter bone cool copper ///
>     coolwarm hot {
  2.     local palettes `palettes' matplotlib `scheme' /
  3. }

. colorpalette: `palettes'
Code
colors/matplotlib.svg
[top]

Palettes by Tol (2012)

The ptol palette provide some color schemes suggested by Tol (2012). The selection of colors depends on the size of the palette:

. colorpalette: ///
>       ptol,           n(4) / ptol,           n(8) / ptol,           n(12) ///
>     / ptol rainbow,   n(4) / ptol rainbow,   n(8) / ptol rainbow,   n(12) ///
>     / ptol diverging, n(3) / ptol diverging, n(7) / ptol diverging, n(11)
Code
colors/paultol.svg
[top]

D3 category scales

The d3 palette provides some categorical D3.js color schemes (see d3-scale):

. colorpalette: d3 10 / d3 20 / d3 20b / d3 20c
colors/d3.svg
[top]

Semantic colors

The lin palette provides semantic colors suggested by Lin et al. (2013):

. local Turkers carcolor food features activities

. local Expert fruits vegetables drinks brands

. foreach g in Turkers Expert {
  2.     foreach p in ``g'' {
  3.         colorpalette lin `p', nograph
  4.         local clab
  5.         forv i = 1/`r(n)' {
  6.             local lbl `"`r(p`i'name)'"'
  7.             if strlen(`"`lbl'"')>11 {
  8.                 mata: st_local("lbl", mm_invtokens(mm_pieces(`"`lbl'"', 11), 1))
  9.             }
 10.             else {
 11.                 local lbl `""`lbl'" """'
 12.             }
 13.             local clab `clab' `i' `"`lbl'"'
 14.         }
 15.         if "`p'"=="vegetables" local tplace ", place(1) span"
 16.         else                   local tplace
 17.         colorpalette, plab(`g' Alg.) lc(black) vertical title(`p'`tplace') ///
>             gropts(ylab(`clab') graphr(m(l=0)) aspectratio(3, place(3)) ///
>             name(`p', replace) nodraw): lin `p' / lin `p' algorithm
 18.     }
 19. }

. graph combine `Turkers' `Expert', rows(2) graphr(margin(zero)) ///
>     ysize(5) xsize(6.875)
Code
colors/semantic.svg

The semantic palettes come in two versions: algorithm selected vs. Turkers or expert selected. For example, lin food is the Turkers-selected food colors palette, whereas lin food algorithm is the algorithm-selected food colors palette.

[top]

Colors from spmap

The spmap palette provides some color schemes found in spmap by Maurizio Pisati:

. colorpalette, n(16): ///
>     spmap blues / spmap greens / spmap greys / spmap reds / ///
>     spmap rainbow / spmap heat / spmap terrain / spmap topological
Code
colors/spmap.svg
[top]

Swiss Federal Statistical Office

The sfso palette provides a number of color schemes used by the Swiss Federal Statistical Office. The schemes look as follows:

. local palettes

. foreach scheme in brown orange red pink purple violet blue ltblue ///
>     turquoise green olive black parties languages votes {
  2.     local palettes `palettes' sfso `scheme' /
  3. }

. colorpalette: `palettes'
Code
colors/SFSO.svg

Schemes brown to black are sequential schemes that are often used by the SFSO in line plots and bar graphs. Here is an example (using grstyle to change the look of the graph and assign the colors):

. grstyle init

. grstyle color background white

. grstyle linewidth major_grid thin

. grstyle set color black*.08: plotregion plotregion_line

. grstyle set color gs8: axisline tick major_grid

. grstyle set horizontal

. grstyle set legend 2, nobox stack klength(10)

. grstyle set color sfso orange

. sysuse uslifeexp, clear
(U.S. life expectancy, 1900-1999)

. foreach v in le_wfemale le_wmale le_bfemale le_bmale {
  2.     label variable `v' `"`=substr("`:var lab `v''",18,.)'"'
  3. }

. line le_wfemale le_wmale le_bfemale le_bmale year, lw(*2.5 ..) ///
>     ytitle(Life expectancy)
Code
colors/SFSOorange.svg

parties and languages are semantic schemes for Swiss parties and for the official languages of Switzerland (plus English). The colors for parties are as follows:

. colorpalette sfso parties
colors/SFSOparties.svg

votes is used for results from popular votes. The following example displays the results (percent yes) of the 2012 popular initiative against mass immigration by canton (using shape data from the SFSO):

. clear all

. set obs 26
number of observations (_N) was 0, now 26

. gen byte _ID = _n

. matrix Yes = ///
>   (47.3, 51.1, 53.3, 58.2, 63.1, 59.1, 58.8, 59.4, 49.9, 48.5, 54.6, 39.0, 50.6, ///
>    58.1, 54.4, 63.5, 55.9, 50.6, 55.2, 57.8, 68.2, 38.9, 48.3, 39.3, 39.1, 44.1)'

. svmat Yes

. colorpalette sfso votes, select(2/4 7/10) nograph

. spmap Yes using cantons, id(_ID) legstyle(2) legend(pos(11)) ///
>     polygon(data(lakes) fcolor(ltblue*.8) ocolor(ebblue*.7) osize(vthin)) ///
>     clmethod(custom) clbreaks(35 40 45 50 55 60 65 70) fcolor(`r(p)') ///
>     osize(vthin ..) ocolor(gs8 ..) graphregion(color(gs14))
Code
colors/SFSOvotes.svg
[top]

HTML and W3.CSS colors

colorpalette also features a variety of palettes containing HTML colors or colors from W3.CSS. See the help file for more information. For example, various W3.CSS Color Themes are supported:

. local palettes

. foreach scheme in amber black blue blue-grey brown cyan dark-grey ///
>     deep-orange deep-purple green grey indigo khaki light-blue ///
>     light-green lime orange pink purple red teal yellow {
  2.     local palettes `palettes' w3 `scheme' /
  3. }

. colorpalette: `palettes'
Code
colors/w3themes.svg
[top]

Color vision deficiency simulation

The cblind() option can be used to simulate color vision deficiency (deuteranomaly/deuteranopia, protanomaly/protanopia, and tritanomaly/tritanopia). Example:

. colorpalette: ///
>       Set1,                  name(original)      ///
>     / Set1, cblind(.5, deut) name(deuteranomaly) ///
>     / Set1, cblind(.5, prot) name(protanomaly)   ///
>     / Set1, cblind(1, trit)  name(tritanopia)
Code
colors/CVD.svg
[top]

Grayscale conversion

The gscale() option converts colors to gray. Example:

. colorpalette: ///
>       s2,            name(original)  ///
>     / s2, gscale(.5) name(50% gray)  ///
>     / s2, gscale     name(100% gray)
Code
colors/gscale.svg