R語(yǔ)言利用ggplot2繪制QQ圖和箱線圖詳解_第1頁(yè)
R語(yǔ)言利用ggplot2繪制QQ圖和箱線圖詳解_第2頁(yè)
R語(yǔ)言利用ggplot2繪制QQ圖和箱線圖詳解_第3頁(yè)
R語(yǔ)言利用ggplot2繪制QQ圖和箱線圖詳解_第4頁(yè)
R語(yǔ)言利用ggplot2繪制QQ圖和箱線圖詳解_第5頁(yè)
已閱讀5頁(yè),還剩3頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(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ì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論