stata绘图细节调整_29Nov2019

用stata做图时,可能需要调整一些细节。比如图的长宽,换个marker的形状等。因为用的不多,经常是用到的时候想不起来,搜索起来又得费时间,干脆在这里写一个例子。以后用的时候直接来看一眼。这个主要是写给自己用的,懂得人自然懂其价值,也欢迎收藏。

coefplot (enrolled, label(Enrolled group) m(O) mcolor(black) mfcolor(black) msize(*1.5) mlcolor(black)) /// 
(nonenrolled, label(Non-enrolled group) m(O) mcolor(black) mfcolor(white) msize(*1.5) mlcolor(black) lcolor(*2)), /// 
drop(_cons) xline(0,lpattern(dash)) xlabel(-1.5(0.5)0.5) /// 
legend(col(1) pos(11) ring(0)) scheme(s2mono) graphregion(color(white)) /// 
coeflabels( Gender="Female") /// 
scale(*.9) /// 
xsize(4.5) ysize(3.6) /// 
headings(Age = " " 2.Education = "{bf:Education}" 2.Income = "{bf:Income}" /// 
2.Cliniccheck = "{bf:Clinic check-up}" 2.Duration = "{bf:Duration}", gap(-1) labgap(2))  /// 
groups(Age = " "?.Education = " " ?.Income = " " ?.Cliniccheck = " " ?.Duration = " ", gap(1)) 

graph save figure_1.gph, replace
graph export "figure_1.png", as(png) replace 
 logit Adherence Gender Age i.Education i.Income ///
Urbanity i.Cliniccheck Diabete i.Duration BP, or, if Enrollment == 0
estimates store enrolled

 logit Adherence Gender Age i.Education i.Income ///
Urbanity i.Cliniccheck Diabete i.Duration BP, or, if Enrollment == 1
estimates store nonenrolled

coefplot (enrolled, label(enrolled group)) ///
(nonenrolled, label(non-enrolled group)), drop(_cons) xline(0)  ///
xlabel(-1.5(0.5)0.5)

coefplot (enrolled, mlabels(length = 1 "+" * =11 "0"))             ///
         (nonenrolled, mlabels(trunk length = 1 "+" * =11 "0"))   ///
          , drop(_cons) xline(0)                                    ///
          subti("Hypotheses: 0 no effect, + positive effect, - negative effect", size(small))
          
coefplot (enrolled, label(enrolled group)) ///
(nonenrolled, label(non-enrolled group)), drop(_cons) xline(1) ///
xlabel(0(0.5)1.5) eform xtitle(Odds ratio)  

coefplot (enrolled, offset(.15)) (nonenrolled, drop(*#*) offset(-.15)) (nonenrolled, keep(*#*) pstyle(p2)), ///
    xline(0) legend(off) msymbol(D) mfcolor(white) ciopts(lwidth(*2) lcolor(*.9))   ///
    coeflabels(_cons = ”Constant”, wrap(30) notick labcolor(black) labsize(medlarge) labgap(2)) xlabel(-2(1)4)
    
    
coefplot (enrolled, offset(.15)) (nonenrolled, drop(*#*) offset(-.15)) (nonenrolled, keep(*#*) pstyle(p2)), ///
    xline(0) legend(off) msymbol(D) mfcolor(white) ciopts(lwidth(*2) lcolor(*.9))   ///
    grid(between glcolor(black) glpattern(dash))     ///
    coeflabels(_cons = ”Constant”, wrap(30) notick labcolor(black) labsize(medlarge) labgap(2)) xlabel(-2(1)4)
         
coefplot, xline(0) drop(_cons) omitted baselevels ///
    headings(1.Education = ”{bf:Education}” 1.Income = ”{bf:Annual Household Income}” ///
    1.Duration = ”{bf:Duration}” 1.Cliniccheck = ”{bf:Frequency of clinic check-up}”, labcolor(orange))
* boxplot to check if there are outlier

foreach var of varlist a b c {
graph box `var', scheme(s1mono) ylabel(0(4)24) xsize(5) ysize(5)
graph save "`var'.gph", replace
}

graph combine a.gph b.gph c.gph, rows(1) xsize(20) ysize(7)
graph export boxplot.png, replace
* density plot to show the distributions
foreach var of varlist a b c d {
kdensity `var', scheme(s1mono) xtitle("`var'")
graph save "den_`var'.gph", replace
}

graph combine /// 
den_a.gph den_b.gph den_c.gph den_d.gph, /// 
rows(2) xsize(20) ysize(18)

graph export density.png, replace 
clear
set more off
cap log off
input time rural urban
      2005 .77   .94
      2006 .73   .93
      2008 .63   .80
      2009 .57   .81
      2010 .53   .74
end

gen area = urban - rural

tw (connected rural time, msymbol(S)) ///
   (connected urban time) /// 
   (area      area  time, blwidth(*.001)), /// 
   yscale(range(0 1)) ylabel(0(0.1)1, nogrid format(%7.1f))  /// 
   xlabel(2005 2006 2008 2009 2010) xticks(2005 2006 2008 2009 2010) /// 
   plotregion(margin(zero)) scheme(s1color) /// 
   legend(pos(6) ring(1) rows(1) order(2 1) hol(2 3 4)) /// 
   xtitle("") title("")
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。