利用R語言繪制箱線圖

箱線圖(box plot)主要從四分位數(shù)的角度展示數(shù)據(jù)的分布,最大值(Q4)、上四分位(Q3)、中位數(shù)(Q2)、下四分位數(shù)(Q1)和最小值(Q0)5個位置來獲取一維數(shù)據(jù)的分布概況。

1、系統(tǒng)環(huán)境為Windows

官網(wǎng)下載安裝R語言和Rstudio
https://cloud.r-project.org/
https://github.com/rstudio/rstudio

2、安裝繪圖用的r 包ggplot2

設置工作目錄

setwd('I:/R_practice)
install.packages("ggplots")
加載包

3、導入數(shù)據(jù)

library(ggplot2)
library(readxl)
library(ggsignif)
tair_height_length <- read_excel("tair_height_length.xlsx")   excel 表格在當前工作目錄
View(tair_height_length)
(I@DU0TD2)%~IOLP}3E{LWN.png

4、先用基礎函數(shù)boxplot(),繪制箱線圖

boxplot(height ~ type, data= tair_height_length)
image.png

5、再用ggplot2 繪制

p = ggplot(aes(x = height, y = type), data = tair_height_length) + geom_boxplot(outlier.shape = 20) + labs(x= "高度",y= "類型") + coord_flip()+geom_signif(                         # 添加顯著性標簽
  #comparisons=list(c("VI","QF"),c("QF","QB"),c('VI','QF')), # 選擇你想在哪2組上添加標簽
  comparisons=list(c("WT","IAA")),
  step_increase = 0.1,
  test="t.test",                     # "t 檢驗,比較兩組(參數(shù))" = "t.test","Wilcoxon 符號秩檢驗,比較兩組(非參數(shù))" = "wilcox.test"
  map_signif_level=T               # 標簽樣式F為數(shù)字,T為*號
)
print(p)

p = ggplot(aes(x = height, y = type), data = tair_height_length) + geom_boxplot(outlier.shape = 4) + labs(x= "高度",y= "類型") + coord_flip()
print(p)
image.png

6、對數(shù)據(jù)做方差分析

tair_height_length.aov = aov(height ~ type, data = tair_height_length)
summary(tair_height_length.aov)
最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容