我第一次在Stata中创建了几个图表,并且我的图表出现了问题。
我在主轴上创建了条形图,在辅助轴上创建了线图,用于多个区域,然后将所有区域图形整理为一个。当我导出图形时,图像显示条形图之间的宽度不同/间隙不同。所使用的数据集已折叠,以按年份和区域显示2000年至2015年的案例数(条形)。下面的语法(phec = region):
local phec: value label phec
foreach num of numlist 1 2 4/9 {
local label:label `phec' `num'
twoway bar cases year if phec ==`num', yaxis(1) ///
barwidth(0.6) bargap(0.1) color("0 174 158") ///
ylabel(0(200)1000, angle(0) labsize(*1.0) format(%12.0fc)) ///
xlabel(2000(4)2016, angle(30) labsize(*1.0)) ///
ytitle({bf:Number of cases}, size(*1.0)) ///
xtitle({bf:Year}, size(*1.0)) ///
legend(position(6) order(1 3 2) label(1 "Number of cases") ///
label(3 "Rate per 100,000") label(2 "95% CI") rows(1) ///
region(style(none)) size(*0.7) symxsize(*0.6) symysize(*0.7)) ///
|| rarea lowerCI upperCI year if phec ==`num', yaxis(2) color(maroon*0.3) ///
scheme(s1mono) ///
|| line rate year if phec ==`num', yaxis(2) ///
lcolor("152 0 46") lwidth(medthick) msymbol(T) ///
ylabel(0(5)30, labsize(*1.0) angle(0) axis(2)) ///
ytitle({bf:Rate(per 100,000)}, size(*1.0) axis(2)) ///
plotregion(color(none)) ///
plotregion(margin(b=0)) ///
title({bf:`label'}, size(*0.9) ring(1))
graph display, ysize(2) xsize(3.25)
graph save "T:\figure1.2_`num'.gph", replace
}
grc1leg "T:\figure1.2_8.gph" "T:\figure1.2_5.gph" "T:\figure1.2_6.gph" "T:\figure1.2_2.gph" "T:\figure1.2_9.gph" "T:\figure1.2_1.gph" "T:\figure1.2_7.gph" "T:\\figure1.2_4.gph", scheme(s1mono) cols(2) iscale(*0.8)
graph display, ysize(3) xsize(2)
graph save "T:\Fig 1.2 PHECs_shadedCI.gph", replace
graph export "T:\Fig 1.2 PHECs_shadedCI.pdf", replace
graph export "T:\Fig 1.2 PHECs_shadedCI.tif", replace
graph export "T:\Fig 1.2 PHECs_shadedCI.emf", replace
两个PHEC(地区)的数据示例:
year cases rate upperci lowerci phec
2000 150 10.2 10 10.3 1
2001 154 11 10.8 11.1 1
2002 123 11.2 11 11.3 1
2003 156 10.6 10.4 10.7 1
2004 147 10.8 10.6 10.9 1
2005 189 12 11.8 12.1 1
2000 564 15 14.8 15.1 2
2001 231 14.6 14.4 14.7 2
2002 114 15.8 15.6 15.9 2
2003 896 16.9 16.7 17 2
2004 456 12.8 12.6 12.9 2
2005 123 13 12.8 13.1 2