Thanks as always to Kit Baum who maintains SSC, a new package mycolours is available from SSC. The package consists of a single command mycolours and its help file, although the American spelling mycolors can also be used in calling up the command or its help file if you prefer, or are accustomed to, that spelling. (Nevertheless I draw the line at maintaining two almost identical help files.)
This is a small deal but in downplaying the command I want to give a small push to the idea behind the command as of more importance than the particular implementation.
Users of graphics commands know that there are two extreme but compatible ways to tweak details in your graphs. You can specify options on the fly as needed for a particular graph -- or you can use a particular graph scheme that codifies many (or even all) of your own style preferences. Oddly enough when graphics received a total rewrite in Stata 8 in 2003 I was convinced that I would sometime write my own graph scheme, but that never really happened once I discovered that s1color gets me most of the way to where I usually want to be. Incidentally I see a lot of flak on social media (some but not all good-natured) directed at use of Stata's s2color default (most obvious from its blue backdrop) and have to wonder how many of those giving or receiving flak realise that it's only the default and in no sense compulsory (or even recommended).
Use of colour is evidently a frequent example of option choices and/or style preferences. I've been reading for years, for example, that orange and blue work well together -- especially for those who have difficulty distinguishing red and green. And there's a massive literature on colour in several sciences (and beyond) and helpful websites such as colorbrewer2.org
An excellent book by Claus Wilke (which I strongly recommend, as at https://www.amazon.com/gp/customer-reviews/R22MWD7RJ6QAFP) uses one of many available colour palettes, which appears to be due to Okabe and Ito (full reference in the help file). It often works well when the aim is to show different groups differently (but we aren't talking about monotonic scales such as low to high or strong negative to strong positive). But it's defined as a series of RGB triples, and I don't want to have to remember (or to look up) and then to type a series of RGB triples, so what to do?
If you run
you get this output, telling you that local macros have been defined in your namespace (programmers may want to look at the code to see how this is done).
and if you want to see what those colours look like, an understandable desire
shows this graph

The deal now is what you can do. You can type those local macro names in graph commands, and you get the colours so defined.
Here are some examples:
I show here only the last graph.

Naturally, other choices are possible, say different marker symbols too.
If you don't find this palette interesting or useful, and you would prefer some other palette or palettes, you can still think about defining some local macros in the style of mycolours.
This is a small deal but in downplaying the command I want to give a small push to the idea behind the command as of more importance than the particular implementation.
Users of graphics commands know that there are two extreme but compatible ways to tweak details in your graphs. You can specify options on the fly as needed for a particular graph -- or you can use a particular graph scheme that codifies many (or even all) of your own style preferences. Oddly enough when graphics received a total rewrite in Stata 8 in 2003 I was convinced that I would sometime write my own graph scheme, but that never really happened once I discovered that s1color gets me most of the way to where I usually want to be. Incidentally I see a lot of flak on social media (some but not all good-natured) directed at use of Stata's s2color default (most obvious from its blue backdrop) and have to wonder how many of those giving or receiving flak realise that it's only the default and in no sense compulsory (or even recommended).
Use of colour is evidently a frequent example of option choices and/or style preferences. I've been reading for years, for example, that orange and blue work well together -- especially for those who have difficulty distinguishing red and green. And there's a massive literature on colour in several sciences (and beyond) and helpful websites such as colorbrewer2.org
An excellent book by Claus Wilke (which I strongly recommend, as at https://www.amazon.com/gp/customer-reviews/R22MWD7RJ6QAFP) uses one of many available colour palettes, which appears to be due to Okabe and Ito (full reference in the help file). It often works well when the aim is to show different groups differently (but we aren't talking about monotonic scales such as low to high or strong negative to strong positive). But it's defined as a series of RGB triples, and I don't want to have to remember (or to look up) and then to type a series of RGB triples, so what to do?
If you run
Code:
mycolours
Code:
locals defined: OK1 and ora for orange OK2 and sky for sky blue OK3 and bgr for bluish green OK4 and yel for yellow OK5 and blu for blue OK6 and ver for vermilion OK7 and rpu for reddish purple OK8 and bla for black
Code:
mycolours, show
The deal now is what you can do. You can type those local macro names in graph commands, and you get the colours so defined.
Here are some examples:
Code:
sysuse auto, clear mycolours set scheme s1color 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"))
Naturally, other choices are possible, say different marker symbols too.
If you don't find this palette interesting or useful, and you would prefer some other palette or palettes, you can still think about defining some local macros in the style of mycolours.
Comment