Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Access scheme colors in program


From   Thomas Grund <[email protected]>
To   [email protected]
Subject   st: Access scheme colors in program
Date   Mon, 31 Mar 2014 18:33:57 +0200

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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index