楼主: 匿名
20543 212

[Stata] [Stata] 如何添加直角坐标系及极坐标系及SDAS_绘图实例 [推广有奖]

201
niuniuyiwan 在职认证  发表于 2015-10-22 09:37:14
  1. u anorexia, replace
  2. bysort treatment (before after) : gen order1 = _n - _N/2
  3. twoway pcarrow before order1 after order1, pstyle(p1) || ///
  4. scatter before order1, pstyle(p1) ms(O) xla(none) xtitle("") yla(, ang(h)) ///
  5. ytitle("weight, lb") by(treatment, row(1) note("") legend(off)) ///
  6. saving(g12, asis replace)
复制代码

Graph.png



202
niuniuyiwan 在职认证  发表于 2015-10-22 09:38:18
  1. sysuse auto, clear

  2. rcspline mpg weight, gen(mpg2)

  3. twoway scatter mpg weight, ms(Oh) || fpfit mpg weight || ///
  4. line mpg2 weight, lp(dash) sort yti("`: var label mpg'") ///
  5. xti("`: var label weight'") ///
  6. legend(order(2 "fractional polynomial" 3 "restricted cubic spline") pos(1) ring(0) col(1)) yla(, ang(h)) name(g13_1, replace)

  7. twoway scatter mpg weight, ms(Oh) || lowess mpg weight || ///
  8. lpoly mpg weight, lp(dash) sort yti("`: var label mpg'")  ///
  9. xti("`: var label weight'") ///
  10. legend(order(2 "lowess" 3 "local polynomial") pos(1) ring(0) col(1)) yla(, ang(h)) name(g13_2, replace)

  11. graph combine g13_1 g13_2, saving(g13, asis replace)
复制代码

Graph.png



203
niuniuyiwan 在职认证  发表于 2015-10-22 09:40:26
  1. sysuse auto, clear
  2. glm mpg weight, link(power -1)
  3. predict predicted
  4. scatter mpg predicted || function equality = x, lp(dash) ra(predicted) ///
  5. legend(order(2)) ytitle("`: var label mpg'") ///
  6. xtitle("`: var label predicted'") ///
  7. legend(pos(4) ring(0)) yla(, ang(h)) saving(g15, asis replace)
复制代码

g15.png



204
niuniuyiwan 在职认证  发表于 2015-10-22 09:41:49
  1. sysuse auto, clear
  2. stripplot mpg, over(rep78) box(bfcolor(eltgreen) blcolor(white) barw(0.2)) ///
  3. boffset(-0.2) stack h(0.5) separate(foreign) saving(g18, asis replace)
复制代码

Graph.png



205
niuniuyiwan 在职认证  发表于 2015-10-22 09:43:24
  1. sysuse uslifeexp, clear

  2. twoway scatteri 38 1914  38 1918  80 1918 80 1914 , color(blue*0.2)  ///
  3. recast(area) || scatteri 38 1939 38 1945 80 1945 80 1939, recast(area) ///
  4. color(blue*0.2) || connected le year, legend(off) plotregion(margin(b=0 t=0)) ///
  5. ytitle("`: var label le'") yla(, ang(h)) saving(g14, asis replace)
复制代码

Graph.png



206
niuniuyiwan 在职认证  发表于 2015-10-22 09:44:38
  1. sysuse uslifeexp, clear
  2. twoway line le_male le_female year, lc(blue pink) legend(off)  ///
  3. ytitle("life expectancy") yla(, ang(h)) text(79.2 1980 "female", ///
  4. color(pink)) text(71 1976 "male", color(blue)) xtitle("") ///
  5. saving(g21, asis replace)
复制代码

Graph.png



207
niuniuyiwan 在职认证  发表于 2015-10-22 09:45:42
  1. use beniger
  2. gen pos = 3
  3. replace pos = 9 if inlist(year, 1900, 1920)
  4. replace pos = 10 if inlist(year, 1870, 1980)
  5. replace pos = 12 if inlist(year, 1880, 1970)
  6. triplot ag ind tert , c(l) max(100) mlabel(year) mlabvpos(pos) ///
  7. mlabsize(*0.7) clpat(solid) saving(g16, asis replace)
复制代码

Graph.png



208
niuniuyiwan 在职认证  发表于 2015-10-22 09:46:47
  1. use titanic, clear
  2. collapse survived, by(age sex class)

  3. catplot age sex [aw=100*survived], by(class, compact note("") col(1) ) ///
  4. bar(1, blcolor(gs8) bfcolor(pink*.2)) blabel(bar, format(%4.1f) pos(base)) ///
  5. subtitle(, pos(9) ring(1) bcolor(none) nobexpand place(e)) ///
  6. ytitle(% survived from Titanic) ///
  7. var1opts(gap(*0.1) axis(noline)) ///
  8. var2opts(gap(*.2)) ysize(5) yla(none) ysc(noline) ///
  9. plotregion(lcolor(none)) saving(g19, asis replace)
复制代码

Graph.png



209
niuniuyiwan 在职认证  发表于 2015-10-22 09:49:21
  1. u pollutants, clear
  2. local spec clw(medium) msize(*0.8)

  3. #delimit;
  4. twoway conn depth Au, `spec' ms(Oh) cmissing(n) ||
  5. conn depth Cd, `spec' ms(Th)  ||   conn depth As,
  6. `spec' ms(Sh)  ||  conn depth Pb, `spec' ms(O)  
  7. ||  conn depth Cu, `spec' ms(T)   ||    conn depth Zn, `spec' ms(S)     
  8. ysc(reverse r(46 .))  xsc(log) xsc(titlegap(*10)) yla(50(10)90, ang(h))
  9. xla(0.1 0.3 1 3 10 30 100)  ytitle(Depth (cm)) xtitle(Concentration (ppm))
  10. text(48 `=Au[1]' "Au" 48 `=Cd[1]' "Cd" 48 `=As[1]' "As" 48 `=Pb[1]' "Pb"
  11. 48 `=Cu[1]' "Cu"  48 `=Zn[1]' "Zn") legend(off) saving(g20, asis replace) ;
  12. #delimit cr
复制代码

Graph.png



210
niuniuyiwan 在职认证  发表于 2015-11-12 13:15:35
  1. sysuse auto, clear

  2. foreach var of varlist rep78 mpg turn {
  3.   qui count if !missing(`var')
  4.   bys `var': gen frac = _N/r(N)
  5.   gsort -frac
  6.   levelsof `var' if frac>.10

  7.   local wc: word count `r(levels)'
  8.   local plabel ""

  9.   forvalues i=1/`wc' {
  10.     local plabel "`plabel' plabel(`i' name)"
  11.   }

  12.   graph pie, over(`var') `plabel' sort descending ///
  13.   legend(row(3) pos(6)rowgap(*0.3) region(lcolor(none)))

  14.   drop frac
  15. }
复制代码

Graph.png



您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2026-1-23 15:27