Statalist


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

st: [Graphics] how to set the length of an axis?


From   Antoine Terracol <terracol@univ-paris1.fr>
To   statalist@hsphsun2.harvard.edu
Subject   st: [Graphics] how to set the length of an axis?
Date   Fri, 20 Mar 2009 09:07:25 +0100

Dear _all,

I was asked if I could reproduced a graphic like http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=109
in Stata.

Using nlswork.dta, I was able to produce the graph whose code is pasted below.

As you can see, the years are not evenly spaced on the x-axis. In particular, the part between "1" and "2" is much smaller than the rest.

I understand that, in fact, the total width of the sub graphs are all equal, and that the visual difference is due to the presence of the y axis and its legend in the first sub-graph.

Is there a way to set the length of the axis in the first sub graph, or, alternatively, to produce a graph with just the y-axis in such a way that it would look nice?

Best,
Antoine

/*--------------------------------------------*/
clear
set scheme s2mono
webuse nlswork.dta, clear
g wage=exp(ln_wage)
su wage, de
drop if wage>r(p99)
egen t=group(year)
g ti=t+runiform()
g ti2=ti^2
g ti3=ti^3
qreg wage ti ti2 ti3
predict med
qreg wage ti ti2 ti3 , quantile(.95)
predict q95
qreg wage ti ti2 ti3 , quantile(.05)
predict q5

twoway (hist wage if t==1 , fcolor(gs14) plotr(m(zero)) graphregion(margin(zero) color(white)) xlabel(0 "1") xtitle("") ylabel(0(5)20, grid gmin gmax) horiz) (line med q95 q5 ti if t==1, sort xaxis(2) yaxis(2) ylabel(0(5)20, axis(2)) lcolor(black black black) lwidth(thick thick thick) lpattern(solid solid solid) xscale(off axis(2)) yscale(off axis(2)) plotr(m(zero))) , legend(off) saving(a, replace)
local list "a.gph"

local t=2
while `t'<=15 {
twoway (hist wage if t==`t', fcolor(gs14) plotr(m(zero)) graphregion(margin(zero) color(white)) xlabel(0 "`t'") xtitle("") yscale(off) xtitle("") ylabel(0(5)20 , grid gmin gmax) horiz) (line med q95 q5 ti if t==`t', sort xaxis(2) yaxis(2) ylabel(0(5)20, axis(2)) lcolor(black black black) lwidth(thick thick thick) lpattern(solid solid solid) xscale(off axis(2)) yscale(off axis(2)) ) , legend(off) saving(a`t', replace)
	local list "`list' a`t'.gph"
	local t=`t'+1
}
graph combine `list', imargin(0 0 0 0) row(1) graphregion(color(white)) note(t, pos(6))
/*--------------------------------------------------*/

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