help for mycolours

Set a palette of colours through local macros

mycolours
[
,
show
]

mycolors
[
,
show
]

Description

mycolours or mycolors defines a series of local macros
containing RGB triples which define a colour palette suggested by Okabe
and Ito (2008). The idea is that it should be easier to (recall and)
type the local macro names than to (recall and) type the RGB triples.

The following local macros are defined. Defining each colour using two
macro names is not a matter of principle.

OK1 230 159 0
ora 230 159 0
OK2 86 180 233
sky 86 180 233
OK3 0 158 115
bgr 0 158 115
OK4 240 228 66
yel 240 228 66
OK5 0 114 178
blu 0 114 178
OK6 213 94 0
ver 213 94 0
OK7 204 121 167
rpu 204 121 167
OK8 0 0 0
bla 0 0 0

The following longer names may be helpful:

ora means orange
sky means sky blue
bgr means bluish green
yel means yellow
blu means blue
ver means vermilion
rpu means reddish purple
bla means black

When using the local macros, double quotation marks " "
should be added. See the Examples below. Some readers will wonder why
such quotation marks are not included as a part of each definition. The
explanation is that this would frustrate the application of transparency
(added in Stata 15).

Remarks

People preferring or accustomed to the American spelling "colors" may
type that in the command name mycolors. They should feel free to
substitute that mentally when reading this help or in extreme cases to
edit this file to their taste for personal or local use. Once you edit
any file in this package, the package becomes yours and you are
responsible for any problems.

This is an example command, indicative and not definitive. The command
as written for SSC defines a series of local macros for a series of
colours as suggested by Okabe and Ito (2008) and publicised in many
places since, for example by Wong (2011) (without attribution) and by
Wilke (2019) (with full attribution). In practice these colours are
friendly to many people who have some difficulty distinguishing colours.
Such difficulties are often informally if imprecisely and insensitively
called "colour-blindness". The most common and most widely discussed
challenge is distinguishing red and green. The colours in this palette
often work well together, especially for bar charts or other displays
where large patches of strong primary colours may seem unsubtle or even
aggressive.

In the terminology of Brewer (2016) (see also or instead
https://colorbrewer2.org)
this colour scheme is qualitative, not sequential (to encode values that run
from low to high) or diverging (to encode values that run from strong negative
to strong positive). Sequential and diverging schemes are much easier to think
up on the fly (which shouldn't discourage and doesn't disparage code to
pre-define them). See, however, comments on rainbow or spectral schemes such as
those of Light and Bartlein (2004).

Similar ideas are used by others. For example, Hastie, Tibshirani and
Friedman (2009) and Knaflic (2015) emphasise that blue and orange can go
well together.

This is not in competition with the deeper and wider idea that you may
encapsulate your colour and other graph style preferences in a defined
graph scheme.

The use of local macros calls forth the following comments.

1. This command may be reissued at any time to allow users to remind
themselves of the local names.

2. As the command overwrites any local macros with the same names you
will lose any definitions in the same namespace with different meanings.

3. Given the nature of local macros, you not only can but must reissue
this command if working in a different namespace. In particular, a
do-file or program you use or write will not be able to see the local
macros defined in another place, such as a main interactive session or
another do-file or program. This is a standard feature of local macros,
and indeed why they are, as named, local in scope. If desired, see a
longer story at Cox (2020).

If #2 sounds like a problem, #3 is the solution. Local macro definitions
are constructive and destructive only within the same namespace.
Alternatively, if you are in habit of (say) using local macro names like
OK1 but find this command helpful, you may be well advised to edit
the files to do something different.

4. Stata programmers may wish to note within the program code the use of
the non-documented command c_local.

Options

show draws a sample bar chart showing the colours defined. Any
data in memory are preserved and restored.

Examples

You need to run mycolours first so that local macros are defined.

. mycolours

. mycolours, show

. macro list

Now you can invoke those macros in graph commands.

. sysuse auto, clear

. scatter mpg weight, mc("`ora'")

. scatter mpg weight if foreign, mc("`OK1'") || scatter mpg weight if !foreign, mc("`OK2'") legend(order(1 "Foreign" 2 "Domestic"))

. scatter mpg weight if foreign, mc("`OK1'%50") || scatter mpg weight if !foreign, mc("`OK2'%50") legend(order(1 "Foreign" 2 "Domestic"))

Author

Nicholas J. Cox, Durham University

n.j.cox@durham.ac.uk

Acknowledgments

Eric Melse made helpful comments on this help.

References

Brewer, C.A. 2016.
Designing Better Maps: A Guide for GIS Users.
Redlands, CA: Esri Press.

Cox, N.J. 2020. Stata tip 138: Local macros have local scope.
Stata Journal 20: 499-503.

Hastie, T.J., R.J. Tibshirani and J.H. Friedman. 2009.
The Elements of Statistical Learning: Data Mining, Inference, and Prediction.
New York: Springer.

Knaflic, C.N. 2015.
Storytelling with Data: A Data Visualization Guide for Business Professionals.
Hoboken, NJ: John Wiley.

Light, A. and P.J. Bartlein. 2004.
The end of the rainbow? Color schemes for improved data graphics.
Eos 85(40): 385 and 391.
https://agupubs.onlinelibrary.wiley.com/doi/epdf/10.1029/2004EO400002

Okabe, M. and K. Ito. 2008.
Color Universal Design (CUD): How to make figures and presentations that are friendly to colorblind people.
http://jfly.iam.u-tokyo.ac.jp/color
or
http://jfly.uni-koeln.de/color/

Wilke, C.O. 2019.
Fundamentals of Data Visualization: A Primer on Making Informative and Compelling Figures.
Sebastopol, CA: O'Reilly.

Wong, B. 2010. Color coding. Nature Methods 7: 573.
https://www.nature.com/articles/nmeth0810-573.pdf

Wong, B. 2011. Color blindness. Nature Methods 8: 441.
https://www.nature.com/articles/nmeth.1618.pdf