Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Twoway Line Horizontal


From   "Svend Juul" <[email protected]>
To   <[email protected]>
Subject   Re: st: Twoway Line Horizontal
Date   Mon, 27 Nov 2006 10:21:30 +0100

Thorsten wrote:
I am trying to produce a graph which looks very much like a 
population pyramid, i.e. a graph twoway bar with "horizontal" 
option; turning bars sideways. However, I would like to add a
LINE graph to the graph, but "graph twoway line" does not 
allow for any horizontal options, as far as I can see. 
-----------------------------------------------------------
 
Just switch the y and x variables in the -line- specification.
Here is a modification to the population pyramid found at http://www.ats.ucla.edu/stat/stata/library/graphexamples/code/twobar4.htm
 
sysuse pop2000, clear
replace maletotal = -maletotal/1e+6
replace femtotal = femtotal/1e+6

replace malewhite = -malewhite/1e+6   // NEW
replace femwhite = femwhite/1e+6      // NEW
gen zero = 0
 
#delimit ;
twoway 
bar maletotal agegrp, horizontal xvarlab(Males)
||
   bar  femtotal agegrp, horizontal xvarlab(Females)
||
   sc  agegrp zero     , mlabel(agegrp) mlabcolor(black) msymbol(i)
||
   line agegrp malewhite  // NEW
||
   line agegrp femwhite   // NEW
||
, 
xtitle("Population in millions") ytitle("")
plotregion(style(none))
ysca(noline) ylabel(none)
xsca(noline titlegap(-3.5))
xlabel(-12 "12" -10 "10" -8 "8" -6 "6" -4 "4" 4(2)12 , tlength(0) 
grid gmin gmax)
legend(label(1 Males) label(2 Females)) legend(order(1 2))
title("US Male and Female Population by Age, 2000")
note("Source:  U.S. Census Bureau, Census 2000, Tables 1, 2 and 3")
;
#delimit cr

 
Hope this helps
Svend
________________________________________________________ 
 
Svend Juul
Institut for Folkesundhed, Afdeling for Epidemiologi
(Institute of Public Health, Department of Epidemiology)
Vennelyst Boulevard 6 
DK-8000 Aarhus C,  Denmark 
Phone, work:  +45 8942 6090 
Phone, home:  +45 8693 7796 
Fax:          +45 8613 1580 
E-mail:       [email protected] 
_________________________________________________________ 

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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