楼主: 匿名
20426 212

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

111
niuniuyiwan 在职认证  发表于 2015-9-4 10:12:42
  1. //Venn diagram - using pvenn 维恩图之二


  2. ssc install pvenn

  3. clear
  4. input hayfever        eczema        asthma        freq
  5. 1        0        0        31088
  6. 1        1        0        9863
  7. 0        1        0        43522
  8. 0        1        1        9258
  9. 0        0        1        35299
  10. 1        0        1        11024
  11. 1        1        1        6200
  12. 0        0        0        345262
  13. end
  14. list
  15. expand freq
  16. pvenn asthma eczema hayfever
复制代码

Graph.png



112
niuniuyiwan 在职认证  发表于 2015-9-4 10:25:10
  1. //triplot
  2.   
  3. //同时画3个变量值(比例),这三个数值累加为100,如下10+10+80

  4. ssc install triplot

  5. clear

  6. input a1 a2 a3 str10 name

  7. 10 10 80  John

  8. 80 10 10  Fred

  9. 25 25 50  Jane

  10. 90  5  5  Helen

  11. 0  0 100  Ed

  12. 50  25  25  Kate

  13. 20 60 20  Michael

  14. 25 25 50  Darren

  15. 5  90  5  Samar

  16. end

  17. list



  18. triplot a1  a2  a3 , mlab(name) mlabcolor(black) mcolor(blue) ///
  19. mlabsize(*0.9) max(100) title("Opinion a1 a2 a3")
复制代码

Graph.png



113
niuniuyiwan 在职认证  发表于 2015-9-5 10:04:01
  1. //catplot ——描绘类别变量
  2. //修改主题方案
  3. //修改bar为recast


  4. ssc install catplot

  5. set scheme s1color  

  6. sysuse auto, clear

  7. catplot rep78, by(foreign) percent(foreign) recast(bar)
复制代码

Graph.png



114
niuniuyiwan 在职认证  发表于 2015-9-5 10:06:48
  1. //catplot默认为hbar,通过recast修改其余图形
  2. sysuse auto, clear

  3. catplot  rep78, over(for) stack asyvars  perc(for)        ///
  4. blabel(bar, position(center) format(%3.1f)) ///
  5. legend(off)
复制代码

Graph.png



115
niuniuyiwan 在职认证  发表于 2015-9-5 11:21:29
  1. clear all
  2. set more off

  3. input quest str25 q      a1 a2 a3 a4 a5 a6
  4. 1 "Question 1"           0  2  37 45 12 4
  5. 1 "Benchmark Q1"         2  5  25 47 17 4
  6. 2 "Question 2"           1  37  2 40 17 3
  7. 2 "Benchmark Q2"         2  5  25 47  4 17
  8. 3 "Question 3"           1  2  40 37 17 3
  9. 3 "Benchmark Q3"         2  5  25 47 17 4
  10. 4 "Question 4"           1  2  37  17 3 40
  11. 4 "Benchmark Q4"         2  5  47 25 17 4
  12. end       

  13. sort quest q
  14. gen q_sum=_n

  15. label define kk 1 q1 2 b1 3 q2 4 b2 5 q3 6 b3 7 q4 8 b4
  16. label value q_sum kk

  17. reshape long a, i(quest q) j(data)
  18. label var data "Question No."

  19. expand a

  20. split q

  21. replace q2=substr(q2,2,1) if length(q2)>1

  22. catplot  data, over(q1, gap(40) label(labgap(5)))               ///
  23. over(q2 )  stack asyvars perc(q)                                    ///
  24. blabel(bar, size(1) position(center)orient(vert) format(%4.1f)) ///
  25. legend(                                                         ///
  26. label(1 "Missing")                                              ///
  27. label(2 "Never")                                                ///
  28. label(3 "Rarely")                                               ///
  29. label(4 "Occasionaly")                                          ///
  30. label(5 "Mostly")                                               ///
  31. label(6 "Always") rows(1) keygap(0) symxsize(7) bexpand         ///
  32. span size(small))                                               ///
  33. ytitle("Percentage")

  34. exit
复制代码

Graph.png




116
niuniuyiwan 在职认证  发表于 2015-9-6 09:35:47
  1. //tabplot


  2. //Plots categorical variables in the from of a table



  3. ssc install tabplot

  4. sysuse auto, clear

  5. tabplot for rep78, percent(foreign) showval(offset(0.05) format(%2.1f))
复制代码

tabplot.png



117
niuniuyiwan 在职认证  发表于 2015-9-6 09:38:50
  1. //spine

  2. //Plots width proportional to frequency


  3. ssc install spineplot

  4. sysuse auto, clear
  5. spineplot foreign rep78, xti(frequency, axis(1)) ///
  6. xla(0(10)60, axis(1)) xmti(1/69, axis(1))
复制代码

spine2.png



118
niuniuyiwan 在职认证  发表于 2015-9-6 09:40:16
  1. //spine

  2.        
  3. //Plots width proportional to frequency
  4.          
  5. ssc install spineplot

  6. sysuse auto, clear

  7. replace rep78=0 if missing(rep78)

  8. bysort foreign rep78 : gen N   = _N
  9. bysort foreign       : gen Na1 = (N/_N)*100

  10. by foreign : gen N1 = string(Na1,"%5.2f") +"%"

  11. label define kk 0 "missing",
  12. label values rep78 kk

  13. spineplot rep78 foreign, bar1(bcolor(gs14)) ///
  14. percent missing                             ///
  15. bar2(bcolor(gs11))                          ///
  16. bar3(bcolor(gs8))                           ///
  17. bar4(bcolor(gs5))                           ///
  18. bar5(bcolor(gs2))                           ///
  19. bar6(bcolor(red)) text(N1)
复制代码

spine3.png



119
niuniuyiwan 在职认证  发表于 2015-9-6 09:41:13
  1. clear all


  2. input  year   Jan   Feb   March   April   May   June   July   Aug   Sept   Oct   Nov   Dec   Annual   Annual_Fit
  3. 1958 -99.99 -99.99 315.71 317.45 317.50 -99.99 315.86 314.93 313.19 -99.99 313.34 314.67 -99.99 -99.99
  4. 1959 315.58 316.47 316.65 317.71 318.29 318.16 316.55 314.80 313.84 313.34 314.81 315.59 315.98 316.00
  5. 1960 316.43 316.97 317.58 319.03 320.03 319.59 318.18 315.91 314.16 313.83 315.00 316.19 316.91 316.91
  6. 1961 316.89 317.70 318.54 319.48 320.58 319.78 318.58 316.79 314.99 315.31 316.10 317.01 317.65 317.63
  7. 1962 317.94 318.56 319.69 320.58 321.01 320.61 319.61 317.40 316.26 315.42 316.69 317.69 318.45 318.46
  8. 1963 318.74 319.08 319.86 321.39 322.24 321.47 319.74 317.77 316.21 315.99 317.07 318.36 318.99 319.02
  9. 1964 319.57 -99.99 -99.99 -99.99 322.23 321.89 320.44 318.70 316.70 316.87 317.68 318.71 -99.99 319.52
  10. 1965 319.44 320.44 320.89 322.13 322.16 321.87 321.21 318.87 317.81 317.30 318.87 319.42 320.03 320.09
  11. 1966 320.62 321.59 322.39 323.70 324.07 323.75 322.40 320.37 318.64 318.10 319.79 321.03 321.37 321.34
  12. 1967 322.33 322.50 323.04 324.42 325.00 324.09 322.55 320.92 319.26 319.39 320.72 321.96 322.18 322.13
  13. 1968 322.57 323.15 323.89 325.02 325.57 325.36 324.14 322.11 320.33 320.25 321.32 322.90 323.05 323.11
  14. 1969 324.00 324.42 325.64 326.66 327.38 326.70 325.89 323.67 322.38 321.78 322.85 324.12 324.62 324.60
  15. 1970 325.06 325.98 326.93 328.13 328.07 327.66 326.35 324.69 323.10 323.07 324.01 325.13 325.68 325.65
  16. 1971 326.17 326.68 327.18 327.78 328.92 328.57 327.37 325.43 323.36 323.56 324.80 326.01 326.32 326.32
  17. 1972 326.77 327.63 327.75 329.72 330.07 329.09 328.05 326.32 324.84 325.20 326.50 327.55 327.46 327.52
  18. 1973 328.54 329.56 330.30 331.50 332.48 332.07 330.87 329.31 327.51 327.18 328.16 328.64 329.68 329.61
  19. 1974 329.35 330.71 331.48 332.65 333.09 332.25 331.18 329.40 327.44 327.37 328.46 329.58 330.25 330.29
  20. 1975 330.40 331.41 332.04 333.31 333.96 333.59 331.91 330.06 328.56 328.34 329.49 330.76 331.15 331.16
  21. 1976 331.74 332.56 333.50 334.58 334.87 334.34 333.05 330.94 329.30 328.94 330.31 331.68 332.15 332.18
  22. 1977 332.92 333.42 334.70 336.07 336.74 336.27 334.93 332.75 331.58 331.16 332.40 333.85 333.90 333.88
  23. 1978 334.97 335.39 336.64 337.76 338.01 337.89 336.54 334.68 332.76 332.54 333.92 334.95 335.50 335.52
  24. 1979 336.23 336.76 337.96 338.89 339.47 339.29 337.73 336.09 333.91 333.86 335.29 336.73 336.85 336.89
  25. 1980 338.01 338.36 340.08 340.77 341.46 341.17 339.56 337.60 335.88 336.01 337.10 338.21 338.69 338.67
  26. 1981 339.23 340.47 341.38 342.51 342.91 342.25 340.49 338.43 336.69 336.85 338.36 339.61 339.93 339.95
  27. 1982 340.75 341.61 342.70 343.56 344.13 343.35 342.06 339.82 337.97 337.86 339.26 340.49 341.13 341.09
  28. 1983 341.37 342.52 343.10 344.94 345.75 345.32 343.99 342.39 339.86 339.99 341.16 342.99 342.78 342.75
  29. 1984 343.70 344.51 345.28 347.08 347.43 346.79 345.40 343.28 341.07 341.35 342.98 344.22 344.42 344.44
  30. 1985 344.97 346.00 347.43 348.35 348.93 348.25 346.56 344.69 343.09 342.80 344.24 345.56 345.90 345.86
  31. 1986 346.29 346.96 347.86 349.55 350.21 349.54 347.94 345.91 344.86 344.17 345.66 346.90 347.15 347.14
  32. 1987 348.02 348.47 349.42 350.99 351.84 351.25 349.52 348.10 346.44 346.36 347.81 348.96 348.93 348.99
  33. 1988 350.43 351.72 352.22 353.59 354.22 353.79 352.39 350.44 348.72 348.88 350.07 351.34 351.48 351.44
  34. 1989 352.76 353.07 353.68 355.42 355.67 355.13 353.90 351.67 349.80 349.99 351.30 352.53 352.91 352.94
  35. 1990 353.66 354.70 355.39 356.20 357.16 356.22 354.82 352.91 350.96 351.18 352.83 354.21 354.19 354.19
  36. 1991 354.72 355.75 357.16 358.60 359.34 358.24 356.17 354.03 352.16 352.21 353.75 354.99 355.59 355.62
  37. 1992 355.98 356.72 357.81 359.15 359.66 359.25 357.03 355.00 353.01 353.31 354.16 355.40 356.37 356.36
  38. 1993 356.70 357.16 358.38 359.46 360.28 359.60 357.57 355.52 353.70 353.98 355.33 356.80 357.04 357.10
  39. 1994 358.36 358.91 359.97 361.26 361.68 360.95 359.55 357.49 355.84 355.99 357.58 359.04 358.88 358.86
  40. 1995 359.96 361.00 361.64 363.45 363.79 363.26 361.90 359.46 358.06 357.75 359.56 360.70 360.88 360.90
  41. 1996 362.05 363.25 364.03 364.72 365.41 364.97 363.65 361.49 359.46 359.60 360.76 362.33 362.64 362.58
  42. 1997 363.18 364.00 364.57 366.35 366.79 365.62 364.47 362.51 360.19 360.77 362.43 364.28 363.76 363.84
  43. 1998 365.32 366.15 367.31 368.61 369.29 368.87 367.64 365.77 363.90 364.23 365.46 366.97 366.63 366.58
  44. 1999 368.15 368.87 369.59 371.14 371.00 370.35 369.27 366.94 364.63 365.12 366.67 368.01 368.31 368.30
  45. 2000 369.14 369.46 370.52 371.66 371.82 371.70 370.12 368.12 366.62 366.73 368.29 369.53 369.48 369.47
  46. 2001 370.28 371.50 372.12 372.87 374.02 373.30 371.62 369.55 367.96 368.09 369.68 371.24 371.02 371.03
  47. 2002 372.43 373.09 373.52 374.86 375.55 375.41 374.02 371.49 370.71 370.25 372.08 373.78 373.10 373.07
  48. 2003 374.68 375.63 376.11 377.65 378.35 378.13 376.62 374.50 372.99 373.00 374.35 375.70 375.64 375.61
  49. end

  50. rename (Jan-Dec)(m1 m2 m3 m4 m5 m6 m7 m8 m9 m10 m11 m12)
  51. mvdecode m1-m12 , mv(-99.99=.)
  52. reshape long m, i(year) j(month)
  53. cycleplot m month year, mylabels(`c(Months)') xlabel(, angle(45))
复制代码

cycleplot.png



120
niuniuyiwan 在职认证  发表于 2015-9-6 09:47:18
  1. ssc install sliceplot
  2. clear all


  3. input  year   Jan   Feb   March   April   May   June   July   Aug   Sept   Oct   Nov   Dec   Annual   Annual_Fit
  4. 1958 -99.99 -99.99 315.71 317.45 317.50 -99.99 315.86 314.93 313.19 -99.99 313.34 314.67 -99.99 -99.99
  5. 1959 315.58 316.47 316.65 317.71 318.29 318.16 316.55 314.80 313.84 313.34 314.81 315.59 315.98 316.00
  6. 1960 316.43 316.97 317.58 319.03 320.03 319.59 318.18 315.91 314.16 313.83 315.00 316.19 316.91 316.91
  7. 1961 316.89 317.70 318.54 319.48 320.58 319.78 318.58 316.79 314.99 315.31 316.10 317.01 317.65 317.63
  8. 1962 317.94 318.56 319.69 320.58 321.01 320.61 319.61 317.40 316.26 315.42 316.69 317.69 318.45 318.46
  9. 1963 318.74 319.08 319.86 321.39 322.24 321.47 319.74 317.77 316.21 315.99 317.07 318.36 318.99 319.02
  10. 1964 319.57 -99.99 -99.99 -99.99 322.23 321.89 320.44 318.70 316.70 316.87 317.68 318.71 -99.99 319.52
  11. 1965 319.44 320.44 320.89 322.13 322.16 321.87 321.21 318.87 317.81 317.30 318.87 319.42 320.03 320.09
  12. 1966 320.62 321.59 322.39 323.70 324.07 323.75 322.40 320.37 318.64 318.10 319.79 321.03 321.37 321.34
  13. 1967 322.33 322.50 323.04 324.42 325.00 324.09 322.55 320.92 319.26 319.39 320.72 321.96 322.18 322.13
  14. 1968 322.57 323.15 323.89 325.02 325.57 325.36 324.14 322.11 320.33 320.25 321.32 322.90 323.05 323.11
  15. 1969 324.00 324.42 325.64 326.66 327.38 326.70 325.89 323.67 322.38 321.78 322.85 324.12 324.62 324.60
  16. 1970 325.06 325.98 326.93 328.13 328.07 327.66 326.35 324.69 323.10 323.07 324.01 325.13 325.68 325.65
  17. 1971 326.17 326.68 327.18 327.78 328.92 328.57 327.37 325.43 323.36 323.56 324.80 326.01 326.32 326.32
  18. 1972 326.77 327.63 327.75 329.72 330.07 329.09 328.05 326.32 324.84 325.20 326.50 327.55 327.46 327.52
  19. 1973 328.54 329.56 330.30 331.50 332.48 332.07 330.87 329.31 327.51 327.18 328.16 328.64 329.68 329.61
  20. 1974 329.35 330.71 331.48 332.65 333.09 332.25 331.18 329.40 327.44 327.37 328.46 329.58 330.25 330.29
  21. 1975 330.40 331.41 332.04 333.31 333.96 333.59 331.91 330.06 328.56 328.34 329.49 330.76 331.15 331.16
  22. 1976 331.74 332.56 333.50 334.58 334.87 334.34 333.05 330.94 329.30 328.94 330.31 331.68 332.15 332.18
  23. 1977 332.92 333.42 334.70 336.07 336.74 336.27 334.93 332.75 331.58 331.16 332.40 333.85 333.90 333.88
  24. 1978 334.97 335.39 336.64 337.76 338.01 337.89 336.54 334.68 332.76 332.54 333.92 334.95 335.50 335.52
  25. 1979 336.23 336.76 337.96 338.89 339.47 339.29 337.73 336.09 333.91 333.86 335.29 336.73 336.85 336.89
  26. 1980 338.01 338.36 340.08 340.77 341.46 341.17 339.56 337.60 335.88 336.01 337.10 338.21 338.69 338.67
  27. 1981 339.23 340.47 341.38 342.51 342.91 342.25 340.49 338.43 336.69 336.85 338.36 339.61 339.93 339.95
  28. 1982 340.75 341.61 342.70 343.56 344.13 343.35 342.06 339.82 337.97 337.86 339.26 340.49 341.13 341.09
  29. 1983 341.37 342.52 343.10 344.94 345.75 345.32 343.99 342.39 339.86 339.99 341.16 342.99 342.78 342.75
  30. 1984 343.70 344.51 345.28 347.08 347.43 346.79 345.40 343.28 341.07 341.35 342.98 344.22 344.42 344.44
  31. 1985 344.97 346.00 347.43 348.35 348.93 348.25 346.56 344.69 343.09 342.80 344.24 345.56 345.90 345.86
  32. 1986 346.29 346.96 347.86 349.55 350.21 349.54 347.94 345.91 344.86 344.17 345.66 346.90 347.15 347.14
  33. 1987 348.02 348.47 349.42 350.99 351.84 351.25 349.52 348.10 346.44 346.36 347.81 348.96 348.93 348.99
  34. 1988 350.43 351.72 352.22 353.59 354.22 353.79 352.39 350.44 348.72 348.88 350.07 351.34 351.48 351.44
  35. 1989 352.76 353.07 353.68 355.42 355.67 355.13 353.90 351.67 349.80 349.99 351.30 352.53 352.91 352.94
  36. 1990 353.66 354.70 355.39 356.20 357.16 356.22 354.82 352.91 350.96 351.18 352.83 354.21 354.19 354.19
  37. 1991 354.72 355.75 357.16 358.60 359.34 358.24 356.17 354.03 352.16 352.21 353.75 354.99 355.59 355.62
  38. 1992 355.98 356.72 357.81 359.15 359.66 359.25 357.03 355.00 353.01 353.31 354.16 355.40 356.37 356.36
  39. 1993 356.70 357.16 358.38 359.46 360.28 359.60 357.57 355.52 353.70 353.98 355.33 356.80 357.04 357.10
  40. 1994 358.36 358.91 359.97 361.26 361.68 360.95 359.55 357.49 355.84 355.99 357.58 359.04 358.88 358.86
  41. 1995 359.96 361.00 361.64 363.45 363.79 363.26 361.90 359.46 358.06 357.75 359.56 360.70 360.88 360.90
  42. 1996 362.05 363.25 364.03 364.72 365.41 364.97 363.65 361.49 359.46 359.60 360.76 362.33 362.64 362.58
  43. 1997 363.18 364.00 364.57 366.35 366.79 365.62 364.47 362.51 360.19 360.77 362.43 364.28 363.76 363.84
  44. 1998 365.32 366.15 367.31 368.61 369.29 368.87 367.64 365.77 363.90 364.23 365.46 366.97 366.63 366.58
  45. 1999 368.15 368.87 369.59 371.14 371.00 370.35 369.27 366.94 364.63 365.12 366.67 368.01 368.31 368.30
  46. 2000 369.14 369.46 370.52 371.66 371.82 371.70 370.12 368.12 366.62 366.73 368.29 369.53 369.48 369.47
  47. 2001 370.28 371.50 372.12 372.87 374.02 373.30 371.62 369.55 367.96 368.09 369.68 371.24 371.02 371.03
  48. 2002 372.43 373.09 373.52 374.86 375.55 375.41 374.02 371.49 370.71 370.25 372.08 373.78 373.10 373.07
  49. 2003 374.68 375.63 376.11 377.65 378.35 378.13 376.62 374.50 372.99 373.00 374.35 375.70 375.64 375.61
  50. end

  51. rename (Jan-Dec)(m1 m2 m3 m4 m5 m6 m7 m8 m9 m10 m11 m12)
  52. mvdecode m1-m12 , mv(-99.99=.)
  53. reshape long m, i(year) j(month)
  54. sliceplot line month year, slices(4)
复制代码

graph.PNG



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

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