* Coordinate systems, bases cd "Z:\PUBLIC_web\Stataworkshops\Grammer of Graphics\Coordinates" sysuse auto, clear generate maker = substr(make, 1, strpos(make, " ")-1) replace maker = make if strpos(make, " ")==0 graph dot mpg, over(maker) scheme(s1mono) name(g1) graph dot mpg, over(maker, descending sort(mpg)) scheme(s1mono) name(g2) graph combine g1 g2, title("Reorder categorical coordinates") graph export "reorder categories.emf", replace generate weight100=weight/100 graph dot mpg weight100, over(maker, descending sort(mpg)) name(g3) twoway (scatter price mpg) (scatter weight length), name(g4) twoway (scatter price mpg) (scatter weight length, yaxis(2)), name(g5) twoway (scatter price mpg) (scatter weight length, xaxis(2) yaxis(2)), name(g6) graph combine g4 g5 g6, title("Superimposed coordinates") preserve collapse mpg weight, by(maker) gsort -mpg generate makeid = _n /* forvalues i = 1/`=_N' { local lbl = maker[`i'] local glbl `glbl' `i' `" " `lbl' " "' } twoway (scatter makeid mpg, yscale(reverse) ylabel(`glbl', angle(0)) xtitle("mpg")) /// (scatter makeid weight, xaxis(2) xtitle("lbs.", axis(2))), /// ytitle("") legend(label(1 "mean mpg") label(2 "mean weight")) name(g5) */ forvalues i = 1/`=_N' { local lbl = maker[`i'] label define make `i' "`lbl'", add } label values makeid make twoway (scatter makeid mpg, /// first layer yscale(reverse) ylabel(1/23, valuelabel angle(0)) xtitle("mpg")) /// (scatter makeid weight, /// second layer xaxis(2) xtitle("lbs.", axis(2))), /// ytitle("") legend(label(1 "mean mpg") label(2 "mean weight")) name(g7) restore graph combine g3 g7, title("Layered dot plots") graph export "layered dot plots.emf", replace graph drop _all