楼主: 匿名
20421 212

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

131
niuniuyiwan 在职认证  发表于 2015-9-7 20:44:26
  1. //heatmap-Graphs a heatmap.

  2. /*Requires: cbarplot
  3. to download this program type the following on the Stata
  4. command line (if not already loaded):*/
  5. ssc install hmap

  6. //To run the example: copy the following into a do file and run


  7.    // producing the data
  8.        clear all
  9.        set obs 64
  10.        generate n=int(uniform()*10)
  11.        generate x=1+int((_n-1)/8)
  12.        generate y=1+mod((_n-1),8)
  13.        label define xlab 1 "one" 2 "two" 7 "seven" 8 "eight"
  14.        label define ylab 3 "three" 4 "four" 5 "five" 6 "six"
  15.        label value x xlab
  16.        label value y ylab
  17.        table y x [fw=n]
  18.    
  19.    hmap x y n
复制代码

Graph.png



132
niuniuyiwan 在职认证  发表于 2015-9-8 07:14:42
  1. //mm_plot
  2. /*mm_plot is a user written Mata graph command that allow you
  3. to plot a Mata matrix
  4. Requires: moremata
  5. to download this program type the following on the Stata command
  6. line (if not already loaded):.*/  

  7. ssc install moremata

  8. //To run the example: copy the following into a do file and run


  9. set more off
  10. mata:

  11. for(i=0;i<=2*pi()*1000; i++) {

  12.   a=(i/1000)*cos(i/1000)
  13.   a1=(i/1000)*sin(i/1000)

  14. if(i==0) {
  15.   za=a
  16.   za1=a1
  17. }
  18. else {
  19.   za=za\a
  20.   za1=za1\a1
  21. }
  22.   c=za,za1
  23. }

  24. mata: mm_plot(c)

  25. end
复制代码

Graph.png



133
niuniuyiwan 在职认证  发表于 2015-9-8 07:16:11
  1. //Fractal
  2. /*Generates fractals

  3. Requires: fractal
  4. to download this program type the following on the Stata
  5. command line (if not already loaded):*/
  6. ssc install fractal

  7. clear

  8. fractal  ,hs(0,.2,.3,.40,.5,.618,.75,.85,1.0)   ///
  9. vs(0,.25,.2,.35,.25,.516,.366,.42,.2) hr(0 100) ///
  10. vr(0 200) iter(3) savegraph

  11. graph combine _frctl1.gph _frctl2.gph _frctl3.gph
复制代码

Graph.png



134
niuniuyiwan 在职认证  发表于 2015-9-8 07:19:38
  1. // riskplot
  2. /*The riskplot is a graphical aid to the investigation
  3. of the contributions of risk factors on outcomes of interest.
  4. (see SJ Vol 10 No 1)

  5. Requires: riskplot
  6. to download this program type the following on the Stata command
  7. line (if not already loaded):*/
  8. findit gr0044
  9. /*(The all option ensures that the data (data_riskplot.dta)
  10. will also be downloaded)

  11. To run the example: copy the following into a do file and run*/


  12. use d:\StataMP\ado\personal\data\data_riskplot.dta, clear  //自行调整  
  13. set scheme sj

  14. riskplot depr1995 sex sclass if Idep91==1 [pw=wg], path obs        /*
  15.    */ thick(20) c(. red)  title(Risk plot for subjects with mild   /*
  16.    */ or severe depression at baseline) subtitle((results using    /*
  17.    */ sampling weights), margin(b+5)) scale(0.9) ytitle(depression /*
  18.    */ score 1995) saving(riskplotWG, replace)
复制代码

Graph.png



135
niuniuyiwan 在职认证  发表于 2015-9-8 07:20:57
  1. //zmap

  2. /*zmap graphs (or maps) binned values of a variable z with respect to two
  3. variables x and y treated as Cartesian coordinates.

  4. Requires: zmap
  5. to download this program type the following on the Stata
  6. command line (if not already loaded):*/


  7. //To run the example: copy the following into a do file and run

  8. ssc install zmap

  9. //修改color为mcolor
  10. //修改nlswork.dta下载地址
  11. //修正mxla为xla
  12. //色彩暂未修正
  13. use http://www.stata-press.com/data/r11/nlswork.dta, clear

  14. clear all
  15. use nlswork.dta,clear
  16. egen mean = mean(ln_wage), by(age grade)
  17. egen tag = tag(age grade)
  18. label variable mean "mean ln wage"
  19. summarize ln_wage if !missing(age, grade), detail


  20. zmap mean grade age if tag, breaks(.993 1.166 1.361 1.641 ///
  21. 1.964 2.275 2.456) ms(S ..) ysc(on) xsc(on) legend(on pos(3) ///
  22. col(1)) yla(0/18, ang(h)) ytitle(`: var label grade') ///
  23. xla(15(5)45) note("") mcolor(blue blue*0.5 orange*0.3 orange)   
复制代码

Graph.png



136
niuniuyiwan 在职认证  发表于 2015-9-8 07:22:28
  1. //Statplot
  2. /*Statplot is an alternative to graph hplot, graph hbar and graph dot.
  3. It allows grouping on the axis and other options.  

  4. Requires: statplot
  5. to download this program type the following on the Stata command
  6. line (if not already loaded):*/
  7. ssc install statplot

  8. //To run the example: copy the following into a do file and run


  9. webuse systolic, clear

  10. sysuse census, clear
  11. statplot marriage divorce, over(region) s(sum) xpose varnames
复制代码

Graph.png



137
niuniuyiwan 在职认证  发表于 2015-9-8 07:25:25
  1. //tddens
  2. /*Bivariate kernel density graphs over a grid

  3. Requires: tddens
  4. to download this program type the following on the Stata command
  5. line (if not already loaded):*/
  6. ssc install tddens

  7. //To run the example: copy the following into a do file and run


  8. sysuse auto, clear

  9. tddens price mpg, s b
复制代码

h.png



g.png


f.png



138
niuniuyiwan 在职认证  发表于 2015-9-8 07:26:45
  1. //Deviation plots
  2. /*Plots each data point relative to some appropriate mean with a marker
  3. symbol and a spike connecting marker and mean.

  4. Requires: devnplot
  5. to download this program type the following on the Stata command
  6. line (if not already loaded):*/

  7. ssc install devnplot

  8. //To run the example: copy the following into a do file and run


  9. webuse systolic, clear

  10. version 9: anova systolic drug disease drug*disease
  11. predict predict
  12. predict residual, residual

  13. devnplot systolic drug disease, level(predict) superplines
复制代码

Graph.png



139
niuniuyiwan 在职认证  发表于 2015-9-8 07:29:14
  1. //ellip
  2. /*ellip calculates a confidence ellipse from the elliptically
  3. distributed variables yvar and xvar, and then graphs the
  4. confidence ellipse using graph twoway line.

  5. Requires: ellip
  6. to download this program type the following on the Stata command
  7. line (if not already loaded):*/
  8. ssc install ellip

  9. //To run the example: copy the following into a do file and run

  10. sysuse auto, clear

  11. ellip mpg weight, by(foreign, total legend(off)) ///
  12. total tlabel(Total as a by-group) plot(scatter mpg weight)
复制代码

Graph.png



140
niuniuyiwan 在职认证  发表于 2015-9-8 09:02:05
  1. //Density Plot

  2. /*Requires: spgrid, spkde, spmap & mylabels
  3. to download these programs type the following
  4. on the Stata command line (if not already loaded):*/

  5. ssc install spgrid
  6. ssc install spkde
  7. ssc install spmap
  8. ssc install mylabels

  9. *------------------------------------------------

  10. * 1. Normalize variables in the range [0,1]       

  11. sysuse "auto.dta", clear
  12. set more off

  13. summarize price mpg
  14. clonevar x = mpg
  15. clonevar y = price
  16. replace x = (x-0) / (50-0)
  17. replace y = (y-0) / (20000-0)
  18. mylabels 0(10)50, myscale((@-0) / (50-0)) local(XLAB)
  19. mylabels 0(5000)20000, myscale((@-0) / (20000-0)) local(YLAB)

  20. keep x y
  21. save "xy.dta", replace

  22. * 2. Generate a 100x100 grid

  23. spgrid, shape(hexagonal) xdim(100) ///
  24. xrange(0 1) yrange(0 1)  ///
  25. dots replace   ///
  26. cells("2D-GridCells.dta")  ///
  27. points("2D-GridPoints.dta") ///

  28. * 3. Estimate the bivariate probability density function

  29. spkde using "2D-GridPoints.dta", ///
  30. xcoord(x) ycoord(y)                 ///
  31. bandwidth(fbw) fbw(0.1) dots        ///
  32. saving("2D-Kde.dta", replace)

  33. * 4. Draw the density plot

  34. use "2D-Kde.dta", clear
  35. recode lambda (.=0)
  36. spmap lambda using "2D-GridCells.dta",  ///
  37. id(spgrid_id) clnum(20) fcolor(Rainbow) ///
  38. ocolor(none ..) legend(off)             ///
  39. point(data("xy.dta") x(x) y(y))         ///
  40. freestyle aspectratio(1)                ///
  41. xtitle(" " "Mileage (mpg)")             ///
  42. xlab( `XLAB')                           ///
  43. ytitle(" " "Price ({c S|}US)")          ///
  44. ylab(`YLAB', angle(0))

  45. exit
复制代码

Graph.png



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

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