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

 

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