Plotting with the BuRd scheme

Alternative Stata graph schemes got briefly mentioned in the opening post when I linked to the BuRd scheme, my own realization in that domain. Solomon Hsiang recently published his own scheme, which he uses to plot the neat graph functions that he codes for both Matlab and Stata. This post explains a bit further what I have been trying to achieve with the BuRd scheme.

Update: the BuRd scheme is now available from GitHub and from Stata, with the following command:

ssc install scheme-burd, replace

Stata graphs are not the nicest part of the software. What Stata wins on making it possible to recode or regress a set of variables in one line, it loses when it comes to making the look of a plot a bit cleaner or simply more elegant. Stata graph syntax is rather usable, but the default schemes are rarely satisfactory. Here, for instance, are a few default families applied to a scatterplot:

sysuse lifeexp, clear
gr drop _all

local l "s2color s2mono s1color s1mono sj economist"

foreach s of local l {
    sc lexp safewater, ti(`s') scheme(`s') name(`s')
}

gr combine `l', row(2) name(dots)
gr export dots.png, replace

The default schemes have a few undesirable issues, like perpendicular reading on the y-axis, that have been fixed in the Economist-like scheme. That scheme also wins a few more points on its discrete color selection, which is hard-coded in Stata’s color styles:

sysuse lifeexp, clear
gr drop _all

local l "s2color s2mono s1color s1mono sj economist"

gen x = lexp^3
xtile q = x, nq(10)

foreach s of local l {
    gr bar x, over(q) asyvars legend(row(1)) ti(`s') scheme(`s') name(`s', replace)
}

gr combine `l', row(2) name(bars)
gr export bars.png, replace

The issue finally gets to become a real problem when it makes a common visualization of survey data, which is generally full of lowly-dimensional ordinal data like 4-point scales, more difficult than it should ever be:

sysuse lifeexp, clear
gr drop _all

local l "s2color s2mono s1color s1mono sj economist"

gen x = lexp^3
xtile q = x, nq(10)

qui tab region, gen(r_)

local l "s2color s2mono s1color s1mono sj economist"

foreach s of local l {
    gr bar r_*, over(q, sort(1)) stack percent ///
    legend(row(1)) ti(`s') scheme(`s') name(`s', replace)
}

gr combine `l', row(2) name(stacks)
gr export stacks.png, replace

My own take consists in a scheme, burd, that uses some toned-down colors from ColorBrewer and offers a range of diverging scales colored from blue to red tints. The scheme was tested on the common types of plots below, and there are more demo plots at its wiki page.

set scheme burd, perm

sysuse lifeexp, clear
gr drop _all

sc lexp safewater, name(dots)

gen x = lexp^3
xtile q = x, nq(10)

gr bar x, over(q) asyvars legend(row(1)) name(bars)

qui tab region, gen(r_)

gr bar r_*, over(q, sort(1)) stack percent ///
    legend(row(1)) scheme(burd3) name(stacks) 

hist lexp, normal name(hist)
tw sc lexp safewater || lfit lexp safewater, name(lfit)
gr mat lexp safewater popgrowth, name(mat)

gr combine dots bars stacks hist lfit mat, row(2)
gr export burd.png, replace

The scheme uses the default ‘sharper’ graph settings used in Edwin Leuven’s own schemes, which are based on Svend Juul’s lean schemes and on ColorBrewer selections of discrete colors. Another implementation of ColorBrewer is in Maurizio Pisati’s spmap package, and yet another take on Stata graphs is Ulrich Atz’s scheme_tufte package, which mimicks Tufte-like plots.

Ideally, it should be possible to go much further with Stata graphs, and some users are already doing it: Stata News reported no so long ago about the work that was done at the Oxford Internet Institute to produce elegant survey plots from Stata. It should also be mentioned that recent versions of Stata offer more graph features, like margin plots, so future graphic improvement can be hoped for.

  1. perzadook reblogged this from srqm and added:
    FOOLS!
  2. srqm posted this