




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、習題2.1 (1)簡單頻數分布表:> load("D:工作總結人大R語言統計學基于R(第3版)例題和習題數據(公開資源)exercisech2exercise2_1.RData")> summary(exercise2_1) 行業 性別 滿意度 電信業:38 男:58 不滿意:75 航空業:19 女:62 滿意 :45 金融業:26 旅游業:37 二維列聯表:> mytable1<-table(exercise2_1$行業,exercise2_1$滿意度)> addmargins(mytable1)# 增加邊界和 不滿意 滿意 Sum 電信業
2、25 13 38 航空業 12 7 19 金融業 11 15 26 旅游業 27 10 37 Sum 75 45 120三維列聯表:> mytable1<-ftable(exercise2_1, row.vars = c("性別","滿意度"), col.var="行業");mytable1 行業 電信業 航空業 金融業 旅游業性別 滿意度 男 不滿意 11 7 7 11 滿意 6 3 7 6女 不滿意 14 5 4 16 滿意 7 4 8 4(2)條形圖:> count1<-table(exercise2_1
3、$行業)> count2<-table(exercise2_1$性別)> count3<-table(exercise2_1$滿意度)> par(mfrow=c(1,3),mai=c(0.7,0.7,0.6,0.1),cex=0.7,cex.main=0.8)> barplot(count1,xlab="行業",ylab="頻數")> barplot(count2,xlab="性別",ylab="頻數")> barplot(count3,xlab="滿意度&
4、quot;,ylab="頻數")帕累托圖:> count1<-table(exercise2_1$行業)> par(mai=c(0.7,0.7,0.1,0.8),cex=0.8)> x<-sort(count1,decreasing = T)> bar<-barplot(x,xlab="行業",ylab="頻數",ylim=c(0,1.2*max(count1),col=2:5)> text(bar,x,labels = x,pos=3) # 條形圖增加數值> y<-cums
5、um(x)/sum(x) # cumsum累計求和> par(new=T)> plot(y,type="b",lwd=1.5,pch=15,axes=F)> axis(4) # 右Y軸> mtext("累積頻率",side=4,line=3)> mtext("累積分布曲線",line=-2.5,cex=0.8,adj=0.75)復式條形圖:> mytable1<-table(exercise2_1$滿意度,exercise2_1$行業)> barplot(mytable1,xlab=&q
6、uot;行業",ylab="頻數",legend=rownames(mytable1),args.legend=list(x=13), beside = T)脊形圖:> library(vcd)> spine(行業滿意度,data=exercise2_1,xlab="滿意度", ylab="行業",margins=c(4,3.5,1,2.5)馬賽克圖:> mosaicplot(性別+行業+滿意度,data=exercise2_1,col=2:3)(3)餅圖:> count1<-table(exe
7、rcise2_1$行業)> name<-names(count1)> percent<-prop.table(count1)*100> label1<-paste(name," ",percent,"%",sep="")> par(pin=c(3,3),mai=c(0.1,0.4,0.1,0.4),cex=0.8) # 圓的大小> pie(count1,labels=label1,init.angle = 90)扇形圖:> count1<-table(exercise2_1$
8、行業)> name<-names(count1)> percent<-count1/sum(count1)*100> labs<-paste(name," ",percent,"%",sep="")> library(plotrix)> fan.plot(count1,labels=labs,ticks=200)2.2(1)分10組,繪制頻數分布表> load("D:工作總結人大R語言統計學基于R(第3版)例題和習題數據(公開資源)exercisech2exercise2
9、_2.RData")> library(actuar)> v<-as.vector(exercise2_2$燈泡壽命)> gd1<-grouped.data(v, breaks = 10, right = FALSE)> table1<-data.frame(gd1);table1 Var.1 v1 2600, 2800) 12 2800, 3000) 43 3000, 3200) 124 3200, 3400) 135 3400, 3600) 276 3600, 3800) 207 3800, 4000) 198 4000, 4200) 4
10、(2)直方圖> d<-exercise2_2$燈泡壽命> hist(d,breaks=10,xlab="壽命",ylab="頻數")莖葉圖:> stem(exercise2_2$燈泡壽命) The decimal point is 2 digit(s) to the right of the | 26 | 0 28 | 968 30 | 0557882356799 32 | 7888990134569 36 | 033566600024445567788 38 | 22455566670055669 40 | 0010172.3
11、(1)箱線圖:> load("D:工作總結人大R語言統計學基于R(第3版)例題和習題數據(公開資源)exercisech2exercise2_3.RData")> boxplot(exercise2_3,-1,xlab="城市",ylab="氣溫",cex.lab=0.8,cex.axis=0.6) # 從第二列開始,到最后小提琴圖:> library(vioplot)> x1<-exercise2_3$北京> x2<-exercise2_3$沈陽> x3<-exercise2_3
12、$上海> x4<-exercise2_3$南昌> vioplot(x1,x2,x3,x4,names=c("北京","沈陽","上海","南昌")(2)點圖:> library(reshape)> table1_1<-melt(exercise2_3,id.vars=c("月份"),variable_name="城市")> table1_1<-rename(table1_1,c(value="溫度")>
13、 dotchart(table1_1$溫度,groups=table1_1$城市,xlab="溫度",pch=20)> library(lattice)> dotplot(溫度城市,data=table1_1,pch=19)核密度圖:> library(lattice)> dp1<-densityplot(溫度,group=城市,data=table1_1,auto.key=list(columns=1,x=0.01,y=0.95,cex=0.6),cex=0.5)> plot(dp1)> library(sm)> pare(
14、table1_1$溫度,table1_1$城市,lty=1:6,col=1:6)> legend("topleft",legend = levels(table1_1$城市),lty=1:6,col=1:6)(3)輪廓圖> matplot(t(exercise2_3,-1),type="b",xlab="城市",ylab="溫度",pch=1,xaxt="n")> axis(side=1,at=1:10,labels = c("北京","沈陽&qu
15、ot;,"上海","南昌","鄭州","武漢","廣州","???quot;,"重慶","昆明")> legend("bottomright",legend= names(exercise2_3,-1) # 取列名雷達圖:> library(fmsb)> table1<-data.frame(t(exercise2_3,2:11) #行列進行轉換,并數據框> radarchart(table1,a
16、xistype=0,seg=4,maxmin=F,vlabels=exercise2_3,1)> legend(x="topleft",legend=names(exercise2_3,2:11), col=1:10, lty=1:10) #lty圖例(4)星圖:> matrix1<-as.matrix(exercise2_3,2:11)> rownames(matrix1)<-exercise2_3,1> stars(matrix1,key.loc=c(7,2,5),cex=0.8)臉譜圖:> library(aplpack)&g
17、t; faces(t(matrix1),nrow.plot = 5,ncol.plot = 2,face.type = 0)effect of variables: modified item Var "height of face " "1月" "width of face " "2月" "structure of face" "3月" "height of mouth " "4月" "width of mouth &quo
18、t; "5月" "smiling " "6月" "height of eyes " "7月" "width of eyes " "8月" "height of hair " "9月" "width of hair " "10月" "style of hair " "11月" "height of nose " &quo
19、t;12月" "width of nose " "1月" "width of ear " "2月" "height of ear " "3月" 2.4(1)散點圖:> plot(地區生產總值,最終消費支出,xlab="",ylab='最終消費支出')> abline(lm(最終消費支出地區生產總值,data=exercise2_4)> points(固定資產投資,最終消費支出,ylab='最終消費支出
20、39;,pch=2,col="blue")> abline(lm(最終消費支出固定資產投資,data=exercise2_4),col="blue")氣泡圖:> r<-sqrt(最終消費支出/pi)> symbols(最終消費支出,地區生產總值,circles=r, inches=0.3, fg="white",bg="lightblue",ylab="最終消費支出",xlab="地區生產總值")> text(最終消費支出,地區生產總值,rown
21、ames(exercise2_4)> mtext("氣泡大小=最終消費支出",line=-2.5,adj=0.1)(2)星圖:> matrix1<-as.matrix(exercise2_4,2:4)> rownames(matrix1)<-exercise2_4,1> stars(matrix1,key.loc=c(7,2,5),cex=0.8)臉譜圖:> library(aplpack)> faces(matrix1,nrow.plot = 6,ncol.plot = 6,face.type = 0)2.5時序圖:>
22、 load("D:工作總結人大R語言統計學基于R(第3版)例題和習題數據(公開資源)exercisech2exercise2_5.RData")> table1<-ts(exercise2_5,start=2004)> plot(table1,2,xlab="年份",ylab="價格指數",type="n")> points(table1,2,type="o",xlab="年份",ylab="城鎮價格指數")> lines(table1,3,typ
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025屆上海市青浦高中高一物理第二學期期末達標檢測模擬試題含解析
- 2025屆河南省信陽市高級中學物理高二第二學期期末質量檢測模擬試題含解析
- 畢節市餐飲管理辦法細則
- 列車首尾部車門管理辦法
- 潘家口水庫工程管理辦法
- 蘭州市定崗醫師管理辦法
- 潮南區食品安全管理辦法
- 法院執行警械管理辦法
- 銀行抵押業務管理辦法
- 2025屆江蘇省南通市包場中學高二物理第二學期期末學業質量監測模擬試題含解析
- 安全教育培訓:實現安全文明施工
- 2025至2030分布式能源行業市場深度調研及發展規劃及有效策略與實施路徑評估報告
- 反邪教宣講課件
- 2025年全國統一高考英語Ⅰ卷(含答案)
- 1 感受生活中的法律 課件-道德與法治六年級上冊統編版
- 中醫集市活動方案
- 2025年江蘇省南京市中考歷史試卷(含解析)
- 2025年云南普洱市墨江天下一雙文旅體育集團有限公司招聘筆試參考題庫附帶答案詳解
- 新版機動車檢驗檢測機構程序文件模板
- GB∕T 1001.1-2021 標稱電壓高于1000V的架空線路絕緣子 第1部分:交流系統用瓷或玻璃絕緣子元件 定義、試驗方法和判定準則
- DB11_T 1832.9-2022 建筑工程施工工藝規程 第9部分_屋面工程
評論
0/150
提交評論