# Re: st: AW: Graph: Colouring table cells based on conditions or data distribution

 From Austin Nichols To statalist@hsphsun2.harvard.edu Subject Re: st: AW: Graph: Colouring table cells based on conditions or data distribution Date Fri, 16 Oct 2009 10:48:02 -0400

```You can probably also get what you want just with -scatter- putting
squares of some color at the right (x,y) spot and then putting numbers
on top of those; see e.g.
http://www.stata.com/statalist/archive/2009-08/msg00191.html
for some ideas to get started, or try out:

sysuse nlsw88, clear
la var g "Years of education"
ren married m
collapse wage, by(g m)
g w=round(wage,.01)
su wage, meanonly
g c=round((wage-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(ehuge) mc("`c' 100 100")
}
loc g `g'||sc m g, ms(i) mlab(w) mlabp(0)
loc g `g' leg(off) yla(-.75 " " 0 "N" 1 "Y" 1.75 " ", notick)
loc g `g' xla(7 " " 8/18 19 " ", notick)
tw `g' scheme(s1mono) ti(Wage heat map) xsize(8) ysize(5)

On Fri, Oct 16, 2009 at 9:06 AM,  <Stefan.Gawrich@hlpug.hessen.de> wrote:
> Ma*n, thanks for pointing out the talk slides(?) and N*ck for writing them.
> Just looked a bit into them and found some very interesting graphs I didn't see before.
> "Table plots" seem to be a good alternative for colouring.
>
> Nick Cox wrote:
> Colour-coding cells, however, covers at least two kinds of idea:
>
> 1. Qualitative coding: Look! This cell contains a very high value, [...]
> 2. Quantitative coding: Look! In addition to showing you the values, I am also using a series of colour shades. [...]
>
>
> Indeed, color shading like in the given example may not enhance the readability of a table. I also found that the excel algorithm (which I don't know) leads to strange results sometimes.
>
> I use quantitative coding only with few colour categories (beside: I mainly use greys, yellow to brown, purples or - if applicable to the data - traffic lights: green, yellow and red).
>
> One example of the last: 24 regional units deliver data to one dataset I maintain. Last year we had a major shift in data documentation causing a lot of problems inside the regional agencies. After receiving the data I calculated the proportion of missing values for each var by regional unit (>1000 cells) with Stata. I copied the resulting "missing data matrix" to Excel and applied colours (<5%: green; 5- <20%: yellow, 20%+: red). During the process of data preparation I updated this table on a daily basis and it proved to be a valuable tool.
>
> Thanks
>
> St*n

*
*   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/
```