感谢大师兄的帮助!
首先我们看一下输入的数据结构:
分为5组,4种类型
接着我们对输入数据进行处理:
###加载R包
library(dplyr)
###数据转换
df <- a %>% pivot_longer(-group,names_to = "SV_type",values_to = "Count")
转换后的数据格式:
数据分为三组
画图代码:
####可以先画一组
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
最后的结果图
###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_bw() +
theme(panel.grid=element_blank())+
geom_signif(comparisons = compaired,
step_increase = 0.3,
map_signif_level = T, #修改参数map_signif_level=TRUE
test = wilcox.test)
添加显著性后
网友评论