Stata繪圖

*----------------------------------------------*
*====         stata繪製人口金字塔         =====*
*---------------------------------------------*
sysuse pop2000,clear
replace maletotal = -maletotal/1000000
replace femtotal = femtotal/1000000
generate zero = 0
#delimit ;
twoway (bar maletotal agegrp,horizontal)||(bar femtotal agegrp,horizontal)  //horizontal是使條形圖水平放置
	(scatter agegrp zero,msymbol(i) mlabel(agegrp) mlabcolor(black)),   //添加年齡組的標籤
	xlabel(-12 "12" -8 "8" -4 "4" 4 8 12) xtitle("Population in millions",height(0))  //給x軸添加標題,修改標籤,height(0)是把標籤和標題放在一行
	yscale(off) ylabel(,nogrid) legend(order(1 "Male" 2 "Female"))  //去掉y軸,去掉網格線,完善圖例
	title("US Male and Female Population by Age,2000")
	note("Source:U.S. Census Bureau,Census 2000,Tables 1,2 and 3")
	;
#delimit cr

*----------------------------------------------*
*====             stata繪製餅圖           =====*
*---------------------------------------------*
webuse census,clear
#delimit ;
graph pie pop,over(region) pie(2,explode) plabel(2 percent,gap(-10))  //突出顯示順時針第二個扇區,並標註第二個扇區的百分比,可以將percent改爲sum
plabel(_all name,size(*1.5) color(white))  //顯示每個扇區名稱
legend(off)
plotregion(lstyle(none))
title("Polulation by region")
subtitle("1980")
note("Source:1980 Census data by state")
;
#delimit cr

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章