




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
第R語(yǔ)言利用ggplot2繪制QQ圖和箱線圖詳解目錄繪制qq圖函數(shù)介紹例子繪制boxplot函數(shù)介紹例子利用分位點(diǎn)繪制箱線圖將QQ圖和箱線圖進(jìn)行融合函數(shù)介紹參數(shù)介紹注意事項(xiàng)例子
繪制qq圖
在ggplot2中繪制qq圖需要兩步,geom_qq()將繪制樣本分位點(diǎn),geom_qq_line()將繪制標(biāo)準(zhǔn)正態(tài)線
函數(shù)介紹
geom_qq()
geom_qq(
mapping=NULL,
data=NULL,
geom="point",
position="identity",
...,
distribution=stats::qnorm,
dparams=list(),
na.rm=FALSE,
show.legend=NA,
inherit.aes=TRUE
geom_qq_line(
mapping=NULL,
data=NULL,
geom="path",
position="identity",
...,
distribution=stats::qnorm,
dparams=list(),
line.p=c(0.25,0.75),
fullrange=FALSE,
na.rm=FALSE,
show.legend=NA,
inherit.aes=TRUE
參數(shù)介紹
**aes()**中的映射參數(shù)必須包含sample,可選參數(shù)有g(shù)roup,x,ydistribution
Distributionfunctiontouse,ifxnotspecified
dparamsAdditionalparameterspassedontodistributionfunction.
line.pVectorofquantilestousewhenfittingtheQ-Qline,defaultsdefaultstoc(.25,.75).
fullrangeShouldtheq-qlinespanthefullrangeoftheplot,orjustthedata
注意事項(xiàng)
**aes()**中的映射參數(shù)必須包含sample
例子
Usingtoexplorethedistributionofavariable
ggplot(mtcars,aes(sample=mpg))+
stat_qq()+
stat_qq_line()
ggplot(mtcars,aes(sample=mpg,colour=factor(cyl)))+
stat_qq()+
stat_qq_line()
繪制boxplot
geom_boxplot(
mapping=NULL,
data=NULL,
stat="boxplot",
position="dodge2",
...,
outlier.colour=NULL,
outlier.color=NULL,
outlier.fill=NULL,
outlier.shape=19,
outlier.size=1.5,
outlier.stroke=0.5,
outlier.alpha=NULL,
notch=FALSE,
notchwidth=0.5,
varwidth=FALSE,
na.rm=FALSE,
orientation=NA,
show.legend=NA,
inherit.aes=TRUE
參數(shù)介紹
aes()可接收的參數(shù)有:
xory,利用x將會(huì)是橫向箱線圖,y的是縱向lowerorxlowerupperorxuppermiddleorxmiddleyminorxminymaxorxmaxalphacolourfillgrouplinetypeshapesizeweight
notchIfFALSE(default)makeastandardboxplot.IfTRUE,makeanotchedboxplot.Notchesareusedtocomparegroups;ifthenotches
oftwoboxesdonotoverlap,thissuggeststhatthemediansare
significantlydifferent.
notchwidthForanotchedboxplot,widthofthenotchrelativetothebody(defaultstonotchwidth=0.5).
varwidthIfFALSE(default)makeastandardboxplot.IfTRUE,boxesaredrawnwithwidthsproportionaltothesquare-rootsofthe
numberofobservationsinthegroups(possiblyweighted,usingthe
weightaesthetic).
p-ggplot(mpg,aes(x=class,y=hwy))
p+geom_boxplot()
ggplot(mpg,aes(x=hwy,y=class))+geom_boxplot()
p-ggplot(mpg,aes(x=class,y=hwy))
p+geom_boxplot(notch=TRUE,varwidth=TRUE,fill="white",colour="#3366FF")
ggplot(diamonds,aes(carat,price))+
geom_boxplot(aes(group=cut_width(carat,0.25)))
p-ggplot(mpg,aes(x=class,y=hwy))
p+geom_boxplot(outlier.shape=NA)+geom_jitter(width=0.2)
利用分位點(diǎn)繪制箱線圖
y-rnorm(100)
df-data.frame(
x=1,
y0=min(y),
y25=quantile(y,0.25),
y50=median(y),
y75=quantile(y,0.75),
y100=max(y)
ggplot(df,aes(x))+
geom_boxplot(
aes(ymin=y0,lower=y25,middle=y50,upper=y75,ymax=y100),
stat="identity"
將QQ圖和箱線圖進(jìn)行融合
該函數(shù)是來(lái)自于qqboxplot包,因此使用前需要安裝
geom_qqboxplot(
mapping=NULL,
data=NULL,
stat="qqboxplot",
position="dodge2",
...,
outlier.colour=NULL,
outlier.color=NULL,
outlier.fill=NULL,
outlier.shape=19,
outlier.size=1.5,
outlier.stroke=0.5,
outlier.alpha=NULL,
notch=FALSE,
notchwidth=0.5,
varwidth=FALSE,
na.rm=FALSE,
show.legend=NA,
inherit.aes=TRUE
參數(shù)介紹
大部分參數(shù)和geom_qq()和geom_boxplot()中的參數(shù)含義相同
reference_dist表示參數(shù)比較的標(biāo)準(zhǔn)分布名稱(chēng),如果有參數(shù)需要有dparams
compdata用于比較的標(biāo)準(zhǔn)樣本數(shù)據(jù),是個(gè)向量
注意事項(xiàng)
aes()函數(shù)中的y不可缺
library(dplyr)
library(ggplot2)
library(qqboxplot)
simulated_data=tibble(y=c(rnorm(1000,mean=2),rt(1000,16),rt(500,4),
rt(1000,8),rt(1000,32)),
group=c(rep("normal,mean=2",1000),
rep("tdistribution,df=16",1000),
rep("tdistribution,df=4",500),
rep("tdistribution,df=8",1000),
rep("tdistribution,df=32",1000)))
p-ggplot2::ggplot(simulated_data,ggplot2
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 移動(dòng)公司退費(fèi)管理辦法
- 舟山企業(yè)能耗管理辦法
- 土壤檢測(cè)資質(zhì)管理辦法
- 肩周炎的中醫(yī)治療
- 肥胖慢病課件
- 廣東24年一模數(shù)學(xué)試卷
- 瘋狂李老師課堂數(shù)學(xué)試卷
- 巔峰訓(xùn)練初一數(shù)學(xué)試卷
- 東林中學(xué)數(shù)學(xué)試卷
- 廣東到福建中考數(shù)學(xué)試卷
- 人事專(zhuān)員合同范本
- 山東省德州市禹城市2023-2024學(xué)年五年級(jí)下學(xué)期道德與法治期末檢測(cè)試題
- 2024年湖北普通高中學(xué)業(yè)水平選擇性考試地理真題解析(參考版)(解析版)
- 2023年湖北省高級(jí)人民法院及直屬法院招聘雇員制審判輔助人員考試真題
- 神經(jīng)內(nèi)科專(zhuān)科護(hù)士進(jìn)修匯報(bào)
- 危險(xiǎn)化學(xué)品應(yīng)急處置卡
- 金屬材料生物相容性研究
- 幕墻工程施工的重點(diǎn)難點(diǎn)分析及針對(duì)措施
- 新版人教版七年級(jí)全冊(cè)英語(yǔ)單詞表(含音標(biāo))可打印
- 人教版六年級(jí)數(shù)學(xué)下冊(cè)全冊(cè)分層作業(yè)設(shè)計(jì)含答案
- 自動(dòng)駕駛卡車(chē)的應(yīng)用與發(fā)展詳述
評(píng)論
0/150
提交評(píng)論