- *******************************************************************************
- *******************************************************************************
- ***** *****
- ***** *****
- ***** 在Stata中绘制流程图 *****
- ***** *****
- ***** *****
- ***** *****
- *******************************************************************************
- *******************************************************************************
- *Definition of boxes and line styles.
- local osmall = ", box margin(small) size(vsmall)"
- local omain = ", box margin(small)"
- local bc = ", lwidth(medthick) lcolor(black)"
- local bca = ", lwidth(medthick) lcolor(black) mlcolor(black) mlwidth(medthick) msize(medlarge)"
- *Drawing the graph
- twoway /// 1) PCI to draw a box 2) pcarrowi: connecting arrows.
- pci 5.2 0 5.2 6 `bc' || pci 5.2 6 0 6 `bc' || pci 0 6 0 0 `bc' || pci 0 0 5.2 0 `bc' ///
- || pci 3 1.5 3 4.5 `bc' || pci 1.9 1.5 1.9 4.5 `bc' || pci 0.9 1.5 0.9 4.5 `bc' ///
- || pcarrowi 5 3 3.5 3 `bca' ///
- || pcarrowi 4.35 3 4.35 3.35 `bca' ///
- || pcarrowi 3.5 3 3.2 3 `bca' ///
- || pcarrowi 3 3 2.1 3 `bca' ///
- || pcarrowi 1.9 3 1.1 3 `bca' ///
- , /// Text placed using "added text" [ACHTUNG sizes change with content]
- text(5 3 "Assessed for eligibility (n= )" `omain') ///
- text(4.35 4.5 "Excluded ""(n= )" ///
- "Not meeting inclusion criteria " ///
- "(n= )" ///
- "Declined to participate " ///
- "(n= )" ///
- "Other reasons""(n= )" `osmall') ///
- text(3.5 3 "Randomized (n= )" `omain') ///
- text(3.1 3 "Allocation" ) ///
- text(2.5 1.5 "ACTIVE" ///
- "Allocated to intervention""(n=)" ///
- "Received allocated intervention ""(n=XXX)" ///
- "Did not receive allocated intervention " ///
- "(give reasons)" ///
- "(n= )" `osmall') ///
- text(2.5 4.5 "CONTROL" ///
- "Allocated to intervention" ///
- "(n= )""Received allocated intervention " ///
- "(n= )" ///
- "Did not receive allocated intervention " ///
- "(give reasons)" ///
- "(n= )" `osmall') ///
- text(2 3 "Follow-Up" ) ///
- text(1.5 1.5 "Lost to follow-up" ///
- "(give reasons)" ///
- "(n= )" ///
- "Discontinued intervention " ///
- "(give reasons)" ///
- "(n= )" `osmall') ///
- text(1.5 4.5 "Lost to follow-up" ///
- "(give reasons)" ///
- "(n= )" ///
- "Discontinued intervention " ///
- "(give reasons)" ///
- " (n= )" `osmall') ///
- text(1 3 "Analysis" ) ///
- text(0.5 1.5 "Analysed" ///
- "(n= )" ///
- "Excluded from analysis" ///
- "(give reasons)" ///
- "(n= )" `osmall') ///
- text(0.5 4.5 "Analysed" ///
- "(n= )" ///
- "Excluded from analysis " ///
- "(give reasons)" ///
- "(n= )" `osmall') ///
- legend(off) ///
- xlabel("") ylabel("") xtitle("") ytitle("") ///
- plotregion(lcolor(black)) ///
- graphregion(lcolor(black)) xscale(range(0 6)) ///
- xsize(2) ysize(3) /// A4 aspect ratio
- title("Consort Flowchart") ///
- note("{bf: Adapted from:} www.consort-statement.org/consort-statement/flow-diagram" ///
- , size(tiny))
- //graph export "./flowchart.pdf", as(pdf) replace
参考自:https://theesspreckelsen.wordpre ... -consort-flowchart/
2)进一步手动修改的思路:
除了在Stata Graph Editor中可直接编辑外,还可根据需要将图片保存为wmf格式, 插入图片到word中,编辑基本形状和修正连接线:(格式--->绘图工具---->编辑形状----->更改形状)
注:上述xsize(2) ysize(3) 2:3 大致为A4纸宽高比。
- *-以上主要使用text( ,box )/ twoway pci / twoway pcarrowi
- //text( ,box )用法举例
- sysuse auto.dta,clear
- scatter price mpg, text(500 30 "Assessed for eligibility (n= )", box fcolor(blue) color(white))
- //twoway pci 用于描线段
- twoway pci 2 0 2 6 4 0 4 6 0 2 6 2 0 4 6 4 || ///
- scatteri 5 1 3 3, msize(ehuge) ms(X) || ///
- scatteri 5 5 1 5, msize(ehuge) ms(Oh) legend(off)
- //twoway pcarrowi 用法举例
- twoway pcarrowi 0 0 0 1 (3) "3 o'clock" ///
- 0 0 1 0 (12) "12 o'clock", ///
- aspect(1) headlabel plotregion(margin(vlarge))