鄭連虎,在數學學院取得理學學位的文科生,中國人民大學碩博連讀生在讀,山東大學管理學學士、理學學士, R語言中文社區專欄作者

個人公眾號:阿虎定量筆記

往期回顧:R語言繪圖:28個實用程序包全文注釋* 初識Stata,請戳「Stata自學資源」

* 示例參考help文件

* 我用Stata MP14重現了所有示例* 本文以字母順序排序命令* spmap及cycleplot的示例數據鏈接見留言區* 更多用於Stata繪圖的外部命令,歡迎在留言區補充aaplot用於散點的線性或二次擬合,顯示擬合方程及R方

開發者Nicholas J. Cox

[email protected]示例*安裝ssc install aaplot*導入1978年汽車交易的數據

sysuse auto, clear

gen gpm = 1000 / mpglabel var gpm "Gallons per thousand miles"*擬合aaplot gpm weight, name(plot)beamplot用於以均值為支點的「蹺蹺板」圖示

開發者Nicholas J. Cox

[email protected]示例*安裝ssc install beamplot*導入1978年汽車交易的數據

sysuse auto, clear

*繪製以均值為支點的「蹺蹺板」beamplot mpg, by(foreign) over(rep78)bihist繪製雙變數雙向直方圖

開發者Austin Nichols

[email protected]示例*安裝ssc install bihist*導入1978年汽車交易的數據sysuse auto, clear*以汽車裡程數分組,繪製車型的雙向直方圖

bihist mpg, by(foreign)binscatter解決大樣本情況下,散點圖過於擁擠無法直觀解釋的問題

開發者Michael Stepner

[email protected]示例*安裝ssc install binscatter*導入1988年女性調查的數據sysuse nlsw88, clearkeep if inrange(age,35,44) & inrange(race,1,2)*工作年限和工資之間的關係scatter wage tenure,title("Graph produced by Scatter") name(plot1)

binscatter wage tenure

*二次擬合binscatter wage tenure, line(qfit) xscale(range(0,25)) xlabel(0(5)25) ylabel(0(10)40) yscale(range(0,40)) title("Graph produced by Binscatter") name(plot2)graph combine plot1 plot2byhist繪製雙變數單向直方圖

開發者Austin Nichols

[email protected]示例*安裝ssc install byhist*導入1978年汽車交易的數據sysuse auto, clear

*以汽車裡程數分組,繪製車型的單向直方圖

byhist mpg, by(foreign)catplot顯示變數的頻率或百分比

開發者Nicholas J. Cox

[email protected]示例*安裝ssc install catplot*導入1978年汽車交易的數據sysuse auto, clear*指定分類

gen himpg = mpg > 25

label def himpg 1 "mpg > 25" 0 "mpg <= 25"label val himpg himpg*繪製直方圖catplot himpg rep78 foreign*繪製直方圖catplot rep78, over(for) stack asyvars perc(for) blabel(bar, position(center) format(%3.1f)) legend(off)cbarplot顯示頻率的中心條狀圖

開發者Nicholas J. Cox

[email protected]示例*安裝

ssc install cbarplot

*輸入數據clearinput levels freqcores freqblanks freqtools25 21 32 7024 36 52 11523 126 650 54922 159 2342 163321 75 487 51120 176 1090 912

19 132 713 578

18 46 374 26617 550 6182 154116 76 846 34915 17 182 5114 4 51 1413 29 228 13012 135 2227 729endreshape long freq, i(levels) j(kind) string*以百分比形式顯示頻率cbarplot levels kind [fw=freq], percent(levels)cdfplot繪製樣本累積分布函數

開發者Adrian Mander

[email protected]示例*安裝ssc install cdfplot*導入1978年汽車交易的數據sysuse auto, clear*以車長分組,為車型的值指定單獨的樣本累積分布函數cdfplot length [fw=rep78], by(foreign) norm saving(mygraph,replace)ciplot顯示均值和置信區間

開發者Nicholas J. Cox

[email protected]示例*安裝ssc install ciplot*導入美國城市的氣溫數據sysuse citytemp, clear*繪製置信區間ciplot heatdd cooldd, by(division) xla(, ang(45))cmogram以某變數為條件,顯示另一變數的均值、中位數、頻數、比例

示例*安裝

ssc install cmogram*導入1978年汽車交易的數據sysuse auto, clear*以車重為條件,控制汽車價格,顯示汽車裡程數的均值cmogram mpg weight, histopts(bin(5)) lfit cutpoint(3250) lineat(3000 3250 3500) controls(price)cpyxplot繪製指定變數之間的交叉散點圖

開發者Nicholas J. Cox

[email protected]示例*安裝ssc install cpyxplot*導入1978年汽車交易的數據sysuse auto, clear*繪製車型與維修記錄、與里程數、與車圈、與車長的散點圖cpyxplot foreign
ep78 mpg turn lengthcvxhull繪製凸包圖

開發者R Allan Reese

[email protected]示例*安裝ssc install cvxhull*導入1978年汽車交易的數據sysuse auto, cleargen foreign1=foreignlabel define for 1 For 0 Domlabel values foreign1 for*在散點圖中顯示汽車裡程數的範圍及每一個標有組值的點,每組觀測值將計算出最多2層hull並共享一個組值cvxhull mpg weight, group(foreign) hulls(2) scat(mlab(foreign1) mlabpos(c) msym(i) ysc(r(0,60)))cycleplot把時間序列數據中每個周期的值垂直地繪製出來

開發者Nicholas J. Cox

[email protected]示例*安裝ssc install cycleplot*導入美國GNP數據use "D:us_gnp.dta", clear*按季度分解cycleplot gnp96 quarter year, length(4)devnplot顯示數據的平均值偏離

開發者Nicholas J. Cox

[email protected]示例*安裝ssc install devnplot*導入1978年汽車交易的數據sysuse auto, clear*依維修記錄分組標記汽車裡程數的數值及其均值devnplot mpg rep78drarea用不同顏色解決區域重疊覆蓋的問題

開發者Adrian Mander

[email protected]示例*安裝ssc install drarea*導入標普500指數數據sysuse sp500, cleargenerate high2 = high+15*uniform()generate low2 = low+15*uniform()*分顏色繪圖drarea high low high2 low2 date in 1/20eclplot標記置信區間

開發者Roger Newson

[email protected]示例*安裝ssc install eclplotssc install parmestssc install sencode*導入1978年汽車交易的數據sysuse auto, clear*創建一個輸出數據集parmby "xi:regress mpg i.foreign i.rep78", label norestore*創建一個帶有值標籤的數值變數sencode parm,gene(parmid)*使用參數標籤來標記垂直置信區間eclplot estimate min95 max95 parmidellip繪製置信橢圓

開發者Anders Alexandersson

[email protected]示例*安裝ssc install ellip*導入1978年汽車交易的數據sysuse auto, clear*繪製置信橢圓ellip mpg weight, by(foreign, total legend(off)) total tlabel(Total as a by-group) plot(scatter mpg weight)grcomb組合相同類型的多個圖

開發者Alex Gamma

[email protected]示例*安裝ssc install grcomb*導入1978年汽車交易的數據sysuse auto, clear*同時顯示汽車價格、里程數、維修記錄及發動機排量的箱線圖grcomb graph box price mpg rep78 displacement, v(1)hangroot檢查數據分布

開發者Maarten L. Buis

[email protected]示例*安裝ssc install hangroot*導入1988年女性調查的數據sysuse nlsw88, clear*繪製收入的分布曲線hangroot wage,barhmap繪製熱圖

開發者Austin Nichols

[email protected]示例*安裝ssc install hmap*輸入數據clear allset obs 64generate n=int(uniform()*10)generate x=1+int((_n-1)/8)generate y=1+mod((_n-1),8)label define xlab 1 "one" 2 "two" 7 "seven" 8 "eight"label define ylab 3 "three" 4 "four" 5 "five" 6 "six"label value x xlablabel value y ylabtable y x [fw=n]*繪製熱圖hmap x y nlinkplot顯示成對數據的結構

開發者Nicholas J. Cox

[email protected]示例*安裝ssc install linkplot*輸入10個男孩的A和B材料鞋子的數據(Box,Hunter and Hunter,1978)input A B id13.2 14.0 18.2 8.8 210.9 11.2 314.3 14.2 410.7 11.8 56.6 6.4 69.5 9.8 710.8 11.3 88.8 9.3 913.3 13.6 10endrename A wearArename B wearBreshape long wear, string i(id) j(j)encode j, gen(material)*鏈接成對數據linkplot material wear, link(id) yla(1 2, valuelabel) ysc(r(0.5 2.5)) yla(, ang(h))netplot生成社會網路分析的網路圖

示例*安裝

ssc install netplot*導入社會網路數據sysuse network1a,clear*生成網路圖netplot x_c y_c, labelpdplot繪製帕累托圖

開發者Nicholas J. Cox

[email protected]示例*安裝ssc install pdplot*導入1978年汽車交易的數據sysuse auto, clear*繪製汽車裡程數的帕累托圖pdplot mpgplotmatrix繪製矩陣圖

開發者Adrian Mander

[email protected]示例*安裝ssc install plotmatrix*導入1978年汽車交易的數據sysuse auto, clear*線性回歸reg price mpg trunk weight length turn, noconsmat regmat = e(V)*繪製矩陣plotmatrix, m(regmat) c(red) ylabel(,angle(0))sixplot顯示單變數的六種數據診斷及描述性統計圖

開發者Peter. A. Lachenbruch

[email protected]示例*安裝ssc install sixplot*導入預期壽命數據sysuse uslifeexp,clear*生成男性預期壽命的統計圖sixplot le_malespineplot使圖的寬度與頻率呈比例

開發者Nicholas J. Cox

[email protected]示例*安裝ssc install spineplot*導入1978年汽車交易的數據sysuse auto, clear*繪製直方圖spineplot foreign rep78spmap繪製等值線地圖、比例符號地圖等地圖

開發者Maurizio Pisati

[email protected]示例*安裝ssc install spmap*導入義大利地圖數據use "D:Italy-RegionsData.dta", clear*繪製義大利地圖spmap relig1 using "D:Italy-RegionsCoordinates.dta", id(id)statplot在不藉助圖例的情況下,使用坐標軸標記數據

開發者Eric A. Booth

[email protected] J. [email protected]示例*安裝ssc install statplot*導入人口調查的數據sysuse census, clear*顯示不同地區的結婚數與離婚數statplot marriage divorce, over(region) s(sum) xposestripplot繪製航線圖

開發者Nicholas J. Cox

[email protected]示例*安裝ssc install stripplot*導入血壓數據sysuse bplong, clearegen group = group(age sex), label*繪製航線圖stripplot bp*, bar over(when) by(group, compact col(1) note("")) ysc(reverse) subtitle(, pos(9) ring(1) nobexpand bcolor(none) placement(e)) ytitle("") xtitle(Blood pressure (mm Hg))*導入1978年汽車交易的數據sysuse auto, clear*繪製航線圖stripplot mpg, over(rep78) stack h(0.5) bar(lcolor(red))*繪製航線圖gen pipe = "|"stripplot price, over(rep78) box(barw(0.3)) ms(none) mla(pipe) boffset(0.3)tabplot直方圖的列聯表示

開發者Nicholas J. Cox

[email protected]示例*安裝ssc install tabplot*導入1978年汽車交易的數據sysuse auto, clear*繪製車型與維修記錄的列聯表tabplot foreign rep78, percent(foreign)tddens繪製網格上的雙變數核密度圖

開發者Austin Nichols

[email protected]示例*安裝ssc install tddens*導入1978年汽車交易的數據sysuse auto, clear*繪製汽車價格和里程數的雙變數核密度圖tddens price mpg, s btriplot繪製三個變數的百分比

開發者Nicholas J. Cox

[email protected]示例*安裝ssc install triplot*輸入數據clearinput a1 a2 a3 str10 name0.10 0.10 0.80 John0.80 0.10 0.10 Fred0.25 0.25 0.50 Jane0.90 0.5 0.5 Helen0.10 0.20 0.70 Ed0.50 0.25 0.25 Kate0.20 0.60 0.20 Michael0.25 0.25 0.50 Darren0.5 0.90 0.5 Samarend*繪製三角圖triplot a1 a2 a3, mlab(name)vioplot繪製小提琴圖

開發者Nick Winter

Austin [email protected]示例*安裝ssc install vioplot*導入1978年汽車交易的數據sysuse auto, clear*繪製小提琴圖vioplot mpg, over(rep78) horizontal name(myplot)zmap定義笛卡爾坐標,特別針對空間數據的處理

開發者Nicholas J. Cox

[email protected]示例*安裝ssc install zmap*導入1988年女性調查的數據sysuse nlsw88, clear*生成工資、當前職級與年齡的直角坐標系zmap wage age grade, ms(S ..) ysc(on) xsc(on)大家都在看2017年R語言發展報告(國內)精心整理 | R語言中文社區歷史文章合集(作者篇)精心整理 | R語言中文社區歷史文章整理(類型篇)

公眾號後台回復關鍵字即可學習回復 爬蟲 爬蟲三大案例實戰 回復 Python 1小時破冰入門回復 數據挖掘 R語言入門及數據挖掘回復 人工智慧 三個月入門人工智慧回復 數據分析師 數據分析師成長之路 回復 機器學習 機器學習的商業應用回復 數據科學 數據科學實戰回復 常用演算法 常用數據挖掘演算法


推薦閱讀:
相关文章