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

Re: st: vary marker color by external variable

From   Sergiy Radyakin <>
Subject   Re: st: vary marker color by external variable
Date   Tue, 4 Aug 2009 20:17:01 -0400

Dear Peter,

this is exactly the kind of problem, which can be solved with advanced
graphics programming in Stata - something I presented last week at DC
Stata User Group Meeting. I can send you the slides directly if you
wish, and soon they will be available at the Meeting's proceedings
series. Basically you need to pass a variable all the way through
Stata's graphing engine to reach the drawing routine, then use the
values of this variable to change the marker's color. option -mc()-
expects a color value (constant), not a variable of color values
(vector of data).

1) program the graphics yourself: have a look at -twoway parea-, it is
released at SSC
2) use bubble diagram, size of the bubble (not color) proportional to the weight
3) if you have a limited number of points and/or colors - serialize
them into a sequence of overlapped plots:
sysuse auto
* one long line follows:
twoway scatter price length if rep78==1, mc(green) || scatter price
length if rep78==2, mc(blue) || scatter price length if rep78==3,
mc(maroon) || scatter
price length if rep78==4, mc(red) || scatter price length if rep78==5,
mc("200 200 200")
*end of one long line

Before that generate a categorical variable, similar to rep78 above
based on the weight-class, using e.g. egen. Also note that here you
can use R-G-B colors, don't forget to take them in quotes.

Is this kind of a graph interesting for many people? Please, kindly let me know.

Best regards,
    Sergiy Radyakin
    Consultant, The World Bank

On Tue, Aug 4, 2009 at 3:59 PM, Peter Goff<> wrote:
> I'm looking for a way to use the color of the marker as an added dimension
> in a scatter plot. I realize I can create N plots, all with different
> colors, but I was hoping someone knew of a command to essentially weight
> (continuously) by color. I've tried to use the RGB mcolor(# # #) option, and
> tie the color to the range of my results:
> gen c1 = 255 - (totl-1)*21
> gen c2 = (totl-1)*21
> graph twoway scatter Y X, mcolor("c1 0 c2")
> I cannot, however, get stata to read "c1" as a variable as opposed to a
> class color. Any suggestions would be greatly appreciated.
> Peter Trabert Goff
> PhD student
> Department of Leadership, Policy, and Organizations
> Vanderbilt University
> Peabody #514
> 230 Appleton Place
> Nashville, TN 37203-5721
> Tel. 615-415-7844
> Fax. 615-322-6596
> *
> *   For searches and help try:
> *
> *
> *

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index