分組箱型圖的繪制

感謝大師兄的幫助!
首先我們看一下輸入的數(shù)據(jù)結(jié)構(gòu):


分為5組,4種類型

接著我們對輸入數(shù)據(jù)進(jìn)行處理:

###加載R包
library(tidyr)
library(dplyr)  
###數(shù)據(jù)轉(zhuǎn)換
df <- a %>% pivot_longer(-group,names_to = "SV_type",values_to = "Count")

轉(zhuǎn)換后的數(shù)據(jù)格式:


數(shù)據(jù)分為三組

畫圖代碼:

library(ggplot2)
####可以先畫一組
e <- ggplot(df, aes(x = group, y = Count))
e + geom_boxplot()
####添加分類變量
e2 <- e + geom_boxplot(
  aes(fill = SV_type),
  position = position_dodge(0.9) 
) +
  scale_fill_manual(values = c("#7700FF", "#33ff00","#00AFBB", "#E7B800"))
e2+  theme_bw()+ theme_bw() +
  theme(panel.grid=element_blank())
e2  
最后的結(jié)果圖
###t添加組間多重比較
compaired <- list(c("Aus", "GJ"),
               
                  c("Aus","rufipogon"),
               
                  c("Bas","GJ"),
              
               
                  c("rufipogon","GJ"),
                  c("XI","GJ"), 
                  c("XI","rufipogon"))

e2+theme_bw() +
  theme(panel.grid=element_blank())+
  geom_signif(comparisons = compaired,
              step_increase = 0.3,
              map_signif_level = T, #修改參數(shù)map_signif_level=TRUE
              test = wilcox.test)
添加顯著性后
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

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