




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
本章我們將通過3個具體的實戰例子來綜合展示如何使用R語言來進行數據的可視化。第一個例子主要使用了基本庫函數,第二個例子主要使用了ggplot2函數,第三個例子主要使用了lattice函數。也就是本書主要討論的3個圖形庫。基本庫實戰
plot(faithful)short.eruptions<-with(faithful,faithful[eruptions<3,])
plot(faithful)points(short.eruptions,col="red",pch=19)head(colors(),10)fit<-lm(waiting~eruptions,data=faithful)plot(faithful)lines(faithful$eruptions,fitted(fit),col="blue")abline(v=3,col="purple")abline(h=mean(faithful$waiting))abline(a=coef(fit)[1],b=coef(fit)[2])abline(fit,col="red")plot(LakeHuron,type="l",main='type="l"')x<-seq(0.5,1.5,0.25)y<-rep(1,length(x))plot(x,y,type="n")points(x,y)
with(mtcars,plot(mpg,disp))plot(faithful,main="EruptionsofOldFaithful",xlab="Eruptiontime(min)",ylab="Waitingtimetonexteruption(min)")x<-seq(0.5,1.5,0.25)y<-rep(1,length(x))plot(x,y,main="Effectofcexontextsize")text(x,y+0.1,labels=x,cex=x)old.par<-par(mfrow=c(1,2))plot(faithful,main="Faithfuleruptions")plot(large.islands,main="Islands",ylab="Area")par(old.par)ggplot2實戰
本小節我們使用ggolot2來進行一個實戰展示。我們使用同樣的數據集faithful,首先我們先來繪制基本圖形。使用Geoms和Stats,來定義數據如何使用,以及把數據映射到plot函數里面ggplot(faithful,aes(x=eruptions,y=waiting))+geom_point()+stat_smooth()ggplot(quakes,aes(x=depth))+geom_bar()ggplot(quakes,aes(x=depth))+geom_bar(binwidth=50)
quakes.agg<-aggregate(mag~round(depth,-1),data=quakes,FUN=length)names(quakes.agg)<-c("depth","mag")
ggplot(quakes.agg,aes(x=depth,y=mag))+geom_bar(stat="identity")ggplot(quakes,aes(x=long,y=lat))+geom_point()ggplot(longley,aes(x=Year,y=Unemployed))+geom_line()ggplot(quakes,aes(x=depth))+geom_bar(binwidth=50)ggplot(quakes,aes(x=depth))+stat_bin(binwidth=50)ggplot(longley,aes(x=Year,y=Employed))+geom_point()
ggplot(longley,aes(x=Year,y=Employed))+geom_point()+stat_smooth()
ggplot(longley,aes(x=Year,y=Employed))+geom_point()+stat_smooth(method="lm")ggplot(mtcars,aes(x=hp,y=mpg))+geom_point()
ggplot(mtcars,aes(x=hp,y=mpg))+geom_point()+stat_smooth(method="lm")+facet_grid(~cyl)lattice實戰
這一小節主要展示lattice的綜合使用,我們使用來自mlmRev的Chem97數據集。data(Chem97,package="mlmRev")head(Chem97)leaschoolstudentscoregenderagegcsescoregcsecnt11114F36.6250.3393157211210F-37.6251.3393157311310F-47.2500.9643157411410F-27.5001.214315751158F-16.4440.1583157611610F47.7501.4643157數據集記錄化學考試的學生信息。我們只對以下變量感興趣Score分數:學生的總體分數Gcse分數:學生的GCSE分數gender:學生的性別histogram(~gcsescore,data=Chem97)histogram(~gcsescore|factor(score),data=Chem97)densityplot(~gcsescore|factor(score),Chem97,groups=gender,plot.points=FALSE,auto.key=TRUE)qq(gender~gcsescore|factor(score),Chem97,f.value=ppoints(1
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 關+于媒介體育畸變困境下的媒體自律
- 公司安裝日常管理制度
- 公司等級劃分管理制度
- 公司網銀付款管理制度
- 公司輿情監測管理制度
- 公司資本運作管理制度
- 風管工人安全交底-浪潮-2022.7
- 二次配管開槽及管線敷設安全技術交底
- 2025股權投資合同范本 適用于企業投資協議
- 廣西壯族自治區百色市2023?2024學年高一下冊7月期末教學質量調研測試數學試卷附解析
- 2025年高考真題-化學(黑吉遼卷) 含答案(黑龍江、吉林、遼寧、內蒙古)
- 2025年新高考1卷(新課標Ⅰ卷)英語試卷
- 婦科腔鏡試題及答案
- 語文 《“蛟龍”探海》課件-2024-2025學年統編版語文七年級下冊
- 2025年智慧園區管理知識考試卷及答案
- 2025年企業管理者能力測評試卷及答案
- 車輛維修包干協議書
- 記賬實操-天然氣公司的全盤會計賬務處理實例
- 中學生英語詞匯表3500(全)
- 2025年檔案法制知識競賽題庫(含答案)
- 2025年福建省中考生物沖刺卷模擬檢測卷(含答案)
評論
0/150
提交評論