Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Timothy Mak <tshmak@hku.hk> |
To | "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |
Subject | RE: st: Access scheme colors in program |
Date | Tue, 1 Apr 2014 11:22:03 +0800 |
I was also playing around with the schemes a bit when I was writing my -lgraph.ado-. I discovered that you can type: gr_setscheme [, {scheme}] where {scheme} is the name of a scheme, (and [] means optional) This will then bring up an object called .__SCHEME which you can refer to by typing: classutil des .__SCHEME You'll find that there's a property called .color So if you then type: classutil des .__SCHEME.color You'll find that this then has the properties .p1, .p2, etc., .p15. These give the default sequence of colors used. You can refer to them by as a local, e.g., `__SCHEME.color.p1' Note that for some schemes, the properties are: .p1line, .p2line, etc. instead of .p1, .p2. These are all undocumented, so use at your own risk! Tim -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Winter Sent: 01 April 2014 01:32 To: statalist@hsphsun2.harvard.edu Subject: Re: st: Access scheme colors in program If I'm understanding correctly, you can access the relevant thing by specifying, in quotation marks "scheme whatever", where whatever is the style from which you'd like to draw the color (or whatever): sysuse auto twoway connected weight price , mcolor("scheme p3") or twoway connected weight price , mcolor("scheme p3") mfcolor("scheme background") I'm not sure if this is documented anywhere.. Nick Winter On 3/31/2014 12:33 PM, Thomas Grund wrote: > Dear Statalist > > Short version: Is there a way to get direct access to the color codes > used in -schemes for programming? (long version below) > > Thanks, > Thomas > > > ************************ > Dr Thomas Grund > Marie Curie Fellow > Institute for Futures Studies > Department of Sociology, Stockholm University > > > > Keywords: schemes, programming, twoway > > Long version: > > There are four variables in my dataset (x y z_color z_size) and I > wrote a program that generates and overlays -scatter syntax for each > unique combination of z_color and z_size in such a way that the size > of nodes and the color of the dots correspond to my data. > > Example data: > x y z_color z_size > > 5 5 1 10 > 2 2 1 10 > 5 7 1 20 > 5 7 2 20 > 3 6 2 20 > > Applied to this data my program produces this syntax: > > twoway (scatter x y if z_color = 1 & z_size == 10, msize(10) mcolor(green)) || > (scatter x y if z_color = 1 & z_size == 20, msize(20) mcolor(green)) || > (scatter x y if z_color = 2 & z_size == 20, msize(20) mcolor(blue)) > > As you can see, my program produces one -scatter command for each > unique combination of z_color and z_size. I solved the coloring by > specifying the -mcolor option and drawing from a user-defined color > palette (here, simply green and blue). The program works fine and > does exactly what I want. However, I would like to make the coloring > work with -schemes. That does not seem trivial because schemes define > colors and other styles for overlaid plots (p1 p2....). In the example > above, however, I overlay three plots, but only want to use two > different colors. I would like to access the colors in a -scheme > directly (in a program) and assign some plots (here, the first and > second -scatter command) the same color. One could cheat a little and > solve this by creating a customized -scheme. For example, > > Example scheme : > myscheme.scheme: > > color p1 green > color p2 green > color p3 blue > .... > twoway (scatter x y if z_color = 1 & z_size == 10, msize(10)) || > (scatter x y if z_color = 1 & z_size == 20, msize(20)) || > (scatter x y if z_color = 2 & z_size == 20, msize(20) ), scheme(myscheme) > > However, this is not really a solution for other data. Does anybody > know how I could get access to the colors defined in a scheme within a > program? This must be possible somehow, but it is not documented and I > cannot find anything about it online. > > One solution that comes to my mind is to pre-process a scheme by > reading the .scheme file as text and parse out the color codes that I > want (p1 p2 p3), but this strikes me as overly complicated.... > > Any help would be greatly appreciated. > > Thanks > > Thomas > * > * For searches and help try: > * http://www.stata.com/help.cgi?search > * http://www.stata.com/support/faqs/resources/statalist-faq/ > * http://www.ats.ucla.edu/stat/stata/ > * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/ * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/