Statalist


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

Re: st: vary marker color by external variable


From   Austin Nichols <austinnichols@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: vary marker color by external variable
Date   Wed, 5 Aug 2009 12:32:47 -0400

Peter Goff<peter.t.goff@vanderbilt.edu> :

See also "Between tables and graphs" by Nick Cox (google it) or try e.g.

sysuse nlsw88, clear
g g=max(grade,8)
la var g "Years of education"
ren married m
egen w=mean(wage), by(g m)
su w, meanonly
g c=round((w-r(min))/(r(max)-r(min))*255)
qui levelsof c, loc(cs)
loc g
foreach c of loc cs {
 loc g `"`g' || sc m g if c==`c', ms(S) msize(large) mc("`c' 100 100")"'
 }
tw `g' leg(off) yla(-.5 " " 0 "N" 1 "Y" 1.5 " ") ti(Wage heat map)


On Tue, Aug 4, 2009 at 8:17 PM, Sergiy Radyakin<serjradyakin@gmail.com> wrote:
> 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).
>
> Suggestions:
> 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<peter.t.goff@vanderbilt.edu> 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

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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