R語言ggplot2畫圖風(fēng)暴數(shù)據(jù)分析報告(附代碼數(shù)據(jù))_第1頁
R語言ggplot2畫圖風(fēng)暴數(shù)據(jù)分析報告(附代碼數(shù)據(jù))_第2頁
R語言ggplot2畫圖風(fēng)暴數(shù)據(jù)分析報告(附代碼數(shù)據(jù))_第3頁
R語言ggplot2畫圖風(fēng)暴數(shù)據(jù)分析報告(附代碼數(shù)據(jù))_第4頁
R語言ggplot2畫圖風(fēng)暴數(shù)據(jù)分析報告(附代碼數(shù)據(jù))_第5頁
已閱讀5頁,還剩8頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

R語言ggplot2畫圖風(fēng)暴數(shù)據(jù)分析報告(附代碼數(shù)據(jù))R語言ggplot2畫圖風(fēng)暴數(shù)據(jù)分析報告##加載需要的庫包library("knitr")library("lattice")library("ggplot2")library("gridExtra")現(xiàn)在,數(shù)據(jù)集風(fēng)暴已經(jīng)被加載,如下表所示:setwd("J:/SDSU/Coursera/Reproducibleresearch/Asgn2/strom_data")require("knitr")opts_knit$set(root.dir="J:/SDSU/Coursera/Reproducibleresearch/Asgn2/strom_data")strom<-read.csv("strom_data.csv",sep=",")head(strom)##STATE__BGN_DATEBGN_TIMETIME_ZONECOUNTYCOUNTYNAMESTATE##114/18/19500:00130CST97MOBILEAL##214/18/19500:00145CST3BALDWINAL##312/20/19510:001600CST57FAYETTEAL##416/8/19510:00900CST89MADISONAL##5111/15/19510:001500CST43CULLMANAL##6111/15/19510:002000CST77LAUDERDALEAL##EVTYPEBGN_RANGEBGN_AZIBGN_LOCATIEND_DATEEND_TIMECOUNTY_END##1TORNADO00R語言ggplot2畫圖風(fēng)暴數(shù)據(jù)分析報告(附代碼數(shù)據(jù))全文共13頁,當(dāng)前為第1頁。##2TORNADO00R語言ggplot2畫圖風(fēng)暴數(shù)據(jù)分析報告(附代碼數(shù)據(jù))全文共13頁,當(dāng)前為第1頁。##3TORNADO00##4TORNADO00##5TORNADO00##6TORNADO00##COUNTYENDNEND_RANGEEND_AZIEND_LOCATILENGTHWIDTHFMAGFATALITIES##1014100300##202150200##300.1123200##400100200##500150200##601.5177200##INJURIESPROPDMGPROPDMGEXPCROPDMGCROPDMGEXPWFOSTATEOFFICZONENAMES##11525K0##202.5K0##3225K0##422.5K0##522.5K0##662.5K0R語言ggplot2畫圖風(fēng)暴數(shù)據(jù)分析報告(附代碼數(shù)據(jù))全文共13頁,當(dāng)前為第2頁。##LATITUDELONGITUDELATITUDE_ELONGITUDE_REMARKSREFNUMXX.1X.2R語言ggplot2畫圖風(fēng)暴數(shù)據(jù)分析報告(附代碼數(shù)據(jù))全文共13頁,當(dāng)前為第2頁。##130408812305188061##230428755002##333408742003##434588626004##534128642005##634508748006現(xiàn)在,我們需要修剪數(shù)據(jù)集為我們的目的。這需要從數(shù)據(jù)集中選擇某些變量。變量包括開始數(shù)據(jù)“BGN_DATE”,事件類型“EVTYPE”,死亡人數(shù)“致命”,受傷人數(shù)“受傷”,財產(chǎn)損失“PROPDMG”和作物損害“CROPDMG”。而事件的總結(jié)可以得到如下:#TrimthedatasettorequiredcolumnsonlystormEvent<-strom[,c("BGN_DATE","EVTYPE","FATALITIES","INJURIES","PROPDMG","PROPDMGEXP","CROPDMG","CROPDMGEXP")]R語言ggplot2畫圖風(fēng)暴數(shù)據(jù)分析報告(附代碼數(shù)據(jù))全文共13頁,當(dāng)前為第3頁。summary(stormEvent)R語言ggplot2畫圖風(fēng)暴數(shù)據(jù)分析報告(附代碼數(shù)據(jù))全文共13頁,當(dāng)前為第3頁。##BGN_DATEEVTYPEFATALITIES##5/25/20110:00:1202HAIL:2886120:895266##4/27/20110:00:1193TSTMWIND:2199211:5008##6/9/20110:00:1030THUNDERSTORMWIND:82563:1416##5/30/20040:00:1016TORNADO:605772:1003##4/4/20110:00:1009FLASHFLOOD:542773:316##4/2/20060:00:981FLOOD:253264:167##(Other):897439(Other):172594(Other):694##INJURIESPROPDMGPROPDMGEXPCROPDMG##0:8845660:663188:4674210:880055##1:77565:32649K:4246105:4276##2:313410:22010M:1132010:2381##3:15501:190660:21650:2011##:14952:17865F0:143:1427##4:92725:17695B:401:1404##(Other):4442(Other):131397(Other):120(Other):12316##CROPDMGEXP##:619698##K:281832##M:1994##G4:143R語言ggplot2畫圖風(fēng)暴數(shù)據(jù)分析報告(附代碼數(shù)據(jù))全文共13頁,當(dāng)前為第4頁。##OKLAHOMA,Western,CentralandSoutheast:137R語言ggplot2畫圖風(fēng)暴數(shù)據(jù)分析報告(附代碼數(shù)據(jù))全文共13頁,當(dāng)前為第4頁。##k:21##(Other):45Thedatahasbeenseparatedintotwotypes:1.fatalitiesdata:-whichconsistsofnumberoffatalitiesandinjuriesduetotheevent.2.economicdata:-whichconsistsofamountoflossesonthepropertyandcropincurredduetotheevent.Afterthatthesumofthefatalitiesforeachindividualeventhasbeenclassifiedandrankedindescendingorderandtopfiveeventareselected.Theeventsforthefatalitiesarelistedas:fatalities_data<-subset(strom,strom$FATALITIES!=0&strom$INJURIES!=0,select=c(EVTYPE,FATALITIES,INJURIES))fatalities_list<-aggregate(as.numeric(fatalities_data$FATALITIES),by=list(fatalities_data$EVTYPE),FUN=sum)colnames(fatalities_list)<-c("EVENT","FATALITIES")fatalities_list<-fatalities_list[order(fatalities_list$FATALITIES,decreasing=TRUE),][1:5,]kable(fatalities_list,format="pandoc")EVENTFATALITIES95TORNADO3595265LIGHTNING346498TSTMWIND237626EXCESSIVEHEAT187231FLASHFLOOD1589Similarly,thesumoftheinjuriesforeachindividualeventhasbeenclassifiedandrankedindescendingorderandtopfiveeventareselected.Theeventsfortheinjuriesarelistedas:injury_list<-aggregate(as.numeric(fatalities_data$INJURIES),by=list(fatalities_data$EVTYPE),FUN=sum)colnames(injury_list)<-c("EVENT","INJURIES")R語言ggplot2畫圖風(fēng)暴數(shù)據(jù)分析報告(附代碼數(shù)據(jù))全文共13頁,當(dāng)前為第5頁。R語言ggplot2畫圖風(fēng)暴數(shù)據(jù)分析報告(附代碼數(shù)據(jù))全文共13頁,當(dāng)前為第5頁。injury_list<-injury_list[order(injury_list$INJURIES,decreasing=TRUE),][1:5,]kable(injury_list,format="pandoc")EVENTINJURIES95TORNADO13310965LIGHTNING1350898TSTMWIND986926EXCESSIVEHEAT528053HIGHWIND4864Now,thebarplotfortheabovetabulardatahasbeenconstructedforthebettervisualization.So,theplotisobtainedforthenumberoffatalitiesandinjuriesareshownbelow.Death_plot<-ggplot()+geom_bar(data=fatalities_list,aes(x=EVENT,y=FATALITIES,fill=interaction(FATALITIES,EVENT)),stat="identity",show.legend=F)+theme(axis.text.x=element_text(angle=30,hjust=1))+xlab("HarmfulEvents")+ylab("No.offatailities")+ggtitle("Top5weathereventscausingfatalities")+theme(axis.text.x=element_text(angle=30,hjust=1))Injury_plot<-ggplot()+geom_bar(data=injury_list,aes(x=EVENT,y=INJURIES,fill=interaction(INJURIES,EVENT)),stat="identity",show.legend=F)+theme(axis.text.x=element_text(angle=30,hjust=1))+xlab("HarmfulEvents")+ylab("No.ofINjuries")+ggtitle("Top5weathereventscausingInjuries")+R語言ggplot2畫圖風(fēng)暴數(shù)據(jù)分析報告(附代碼數(shù)據(jù))全文共13頁,當(dāng)前為第6頁。theme(axis.text.x=element_text(angle=30,hjust=1))R語言ggplot2畫圖風(fēng)暴數(shù)據(jù)分析報告(附代碼數(shù)據(jù))全文共13頁,當(dāng)前為第6頁。grid.arrange(Death_plot,Injury_plot,ncol=2)So,itisseenthatfromthefatalitiesdataandtheinjurydata,wecanseethetornadohasthesignificantimpactincamparisiontotheothervariables.Similarly,fortheeconomicdata,welookatthepropertydamageandthecropdamagecausedbythedifferentevents.TheK,M,BvalueonPROPDMGEXPandCROPDMGEXPhasbeenconvertedtonumericvalueto1e3,1e6and1e9.Andthetotaldamagehasbeencalculatedforeacheventandtabulatedinseparatedcolumns.Performingthesimilaranalysis,wecanidentifythetop5eventsforthepropertydamageandcropdamagewhicharetabulatedbelowas:economic_data<-subset(strom,strom$PROPDMG!=0&strom$CROPDMG!=0,select=c(EVTYPE,PROPDMG,PROPDMGEXP,CROPDMG,CROPDMGEXP))economic_data$PROPDMGEXP<-gsub("k",1e+03,economic_data$PROPDMGEXP,ignore.case=TRUE)economic_data$CROPDMGEXP<-gsub("k",1e+03,economic_data$CROPDMGEXP,ignore.case=TRUE)economic_data$PROPDMGEXP<-gsub("m",1e+06,economic_data$PROPDMGEXP,ignore.case=TRUE)R語言ggplot2畫圖風(fēng)暴數(shù)據(jù)分析報告(附代碼數(shù)據(jù))全文共13頁,當(dāng)前為第7頁。economic_data$CROPDMGEXP<-gsub("m",1e+06,economic_data$CROPDMGEXP,ignore.case=TRUE)R語言ggplot2畫圖風(fēng)暴數(shù)據(jù)分析報告(附代碼數(shù)據(jù))全文共13頁,當(dāng)前為第7頁。economic_data$PROPDMGEXP<-gsub("b",1e+09,economic_data$PROPDMGEXP,ignore.case=TRUE)economic_data$CROPDMGEXP<-gsub("b",1e+09,economic_data$CROPDMGEXP,ignore.case=TRUE)economic_data$TOTALPROPDMG<-as.numeric(economic_data$PROPDMG)*as.numeric(economic_data$PROPDMGEXP)##Warning:NAsintroducedbycoercioneconomic_data$TOTALCROPDMG<-as.numeric(economic_data$CROPDMG)*as.numeric(economic_data$CROPDMGEXP)##Warning:NAsintroducedbycoercionPROPDMG_list<-aggregate(as.numeric(economic_data$TOTALPROPDMG),by=list(economic_data$EVTYPE),FUN=sum)colnames(PROPDMG_list)<-c("EVENT","TOTALPROPDMG")PROPDMG_list<-PROPDMG_list[order(PROPDMG_list$TOTALPROPDMG,decreasing=TRUE),][1:5,]kable(PROPDMG_list,format="pandoc")EVENTTOTALPROPDMG59HURRICANE/TYPHOON4.161484e+1264RIVERFLOOD9.546663e+1154HURRICANE7.797388e+1126FLOOD5.050238e+1157HURRICANEOPAL4.304100e+11Similarly,thesumofthelossesduetocropdamageforeachindividualeventhasbeenclassifiedandrankedindescendingorderandtopfiveeventareselected.Theeventsforthecropdamagearelistedas:CROPDMG_list<-aggregate(as.numeric(economic_data$TOTALCROPDMG),by=list(economic_data$EVTYPE),FUN=sum)R語言ggplot2畫圖風(fēng)暴數(shù)據(jù)分析報告(附代碼數(shù)據(jù))全文共13頁,當(dāng)前為第8頁。colnames(CROPDMG_list)<-c("EVENT","TOTALCROPDMG")R語言ggplot2畫圖風(fēng)暴數(shù)據(jù)分析報告(附代碼數(shù)據(jù))全文共13頁,當(dāng)前為第8頁。CROPDMG_list<-CROPDMG_list[order(CROPDMG_list$TOTALCROPDMG,decreasing=TRUE),][1:5,]kable(CROPDMG_list,format="pandoc")EVENTTOTALCROPDMG61ICESTORM30805713200064RIVERFLOOD30798815400059HURRICANE/TYPHOON4346241600026FLOOD4121032200022FLASHFLOOD23634989000Now,thebarplotfortheabovetabulardatahasbeenconstructedforthebettervisualization.So,theplotisobtainedforthenumberoffatalitiesandinjuriesareshownbelow.Propdamage_plot<-ggplot()+geom_bar(data=PROPDMG_list,aes(x=EVENT,y=TOTALPROPDMG,fill=interaction(TOTALPROPDMG,EVENT)),stat="identity",show.legend=F)+theme(axis.text.x=element_text(angle=30,hjust=1))+xlab("HarmfulEvents")+ylab("Amountlostinpropdamage")+ggtitle("Top5weathereventscausingpropdamage")+theme(axis.text.x=element_text(angle=30,hjust=1))Cropdamage_plot<-ggplot()+geom_bar(data=CROPDMG_list,aes(x=EVENT,y=TOTALCROPDMG,fill=interaction(TOTALCROPDMG,EVENT)),stat="identity",show.legend=F)+theme(axis.text.x=element_text(angle=30,hjust=1))+xlab("HarmfulEvents")+ylab("Amountlostincropdamage")+ggtitle("Top5weathereventscausingcropdamage")+R語言ggplot2畫圖風(fēng)暴數(shù)據(jù)分析報告(附代碼數(shù)據(jù))全文共13頁,當(dāng)前為第9頁。theme(axis.text.x=element_text(angle=30,hjust=1))R語言ggplot2畫圖風(fēng)暴數(shù)據(jù)分析報告(附代碼數(shù)據(jù))全文共13頁,當(dāng)前為第9頁。grid.arrange(Propdamage_plot,Cropdamage_plot,ncol=2)So,itisseenthatfromthefatalitiesdataandtheinjurydata,wecanseethetornadohasthesignificantimpactincamparisiontotheothervariables.Similarly,fortheeconomicdata,welookatthepropertydamageandthecropdamagecausedbythedifferentevents.TheK,M,BvalueonPROPDMGEXPandCROPDMGEXPhasbeenconvertedtonumericvalueto1e3,1e6and1e9.Andthetotaldamagehasbeencalculatedforeacheventandtabulatedinseparatedcolumns.Performingthesimilaranalysis,wecanidentifythetop5eventsforthepropertydamageandcropdamagewhicharetabulatedbelowas:economic_data<-subset(strom,strom$PROPDMG!=0&strom$CROPDMG!=0,select=c(EVTYPE,PROPDMG,PROPDMGEXP,CROPDMG,CROPDMGEXP))economic_data$PROPDMGEXP<-gsub("k",1e+03,economic_data$PROPDMGEXP,ignore.case=TRUE)economic_data$CROPDMGEXP<-gsub("k",1e+03,economic_data$CROPDMGEXP,ignore.case=TRUE)economic_data$PROPDMGEXP<-gsub("m",1e+06,economic_data$PROPDMGEXP,ignore.case=TRUE)economic_data$CROPDMGEXP<-gsub("m",1e+06,economic_data$CROPDMGEXP,ignore.case=TRUE)economic_data$PROPDMGEXP<-gsub("b",1e+09,economic_data$PROPDMGEXP,ignore.case=TRUE)economic_data$CROPDMGEXP<-gsub("b",1e+09,economic_data$CROPDMGEXP,ignore.case=TRUE)economic_data$TOTALPROPDMG<-as.numeric(economic_data$PROPDMG)*as.numeric(economic_data$PROPDMGEXP)##Warning:NAsintroducedbycoercioneconomic_data$TOTALCROPDMG<-as.numeric(economic_data$CROPDMG)*as.numeric(economic_data$CROPDMGEXP)##Warning:NAsintroducedbycoercionPROPDMG_list<-aggregate(as.numeric(economic_data$TOTALPROPDMG),by=list(economic_data$EVTYPE),FUN=sum)R語言ggplot2畫圖風(fēng)暴數(shù)據(jù)分析報告(附代碼數(shù)據(jù))全文共13頁,當(dāng)前為第10頁。colnames(PROPDMG_list)<-c("EVENT","TOTALPROPDMG")R語言ggplot2畫圖風(fēng)暴數(shù)據(jù)分析報告(附代碼數(shù)據(jù))全文共13頁,當(dāng)前為第10頁。PROPDMG_list<-PROPDMG_list[order(PROPDMG_list$TOTALPROPDMG,decreasing=TRUE),][1:5,]kable(PROPDMG_list,format="pandoc")EVENTTOTALPROPDMG59HURRICANE/TYPHOON4.161484e+1264RIVERFLOOD9.546663e+1154HURRICANE7.797388e+1126FLOOD5.050238e+1157HURRICANEOPAL4.304100e+11Similarly,thesumofthelossesduetocropdamageforeachindividualeventhasbeenclassifiedandrankedindescendingorderandtopfiveeventareselected.Theeventsforthecropdamagearelistedas:CROPDMG_list<-aggregate(as.numeric(economic_data$TOTALCROPDMG),by=list(economic_data$EVTYPE),FUN=sum)colnames(CROPDMG_list)<-c("EVENT","TOTALCROPDMG")CROPDMG_list<-CROPDMG_list[order(CROPDMG_list$TOTALCROPDMG,decreasing=TRUE),][1:5,]R語言ggplot2畫圖風(fēng)暴數(shù)據(jù)分析報告(附代碼數(shù)據(jù))全文共13頁,當(dāng)前為第11頁。kable(CROPDMG_list,format="pandoc")R語言ggplot2畫圖風(fēng)暴數(shù)據(jù)分析報告(附代碼數(shù)據(jù))全文共13頁,當(dāng)前為第11頁。EVENTTOTALCROPDMG61ICESTORM30805713200064RIV

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論