關(guān)于小提琴圖和柱狀圖的繪制教程很多,在我們前面的教程中也推送過,大家感興趣的可以去看一下。今天,我們繼續(xù)小提琴+柱狀圖的組合圖,且繪制出差異標識。
繪圖
數(shù)據(jù)準備
library(ggpubr)
df <- read.csv("20230306.input.csv",header = T)
head(df)

數(shù)據(jù)根據(jù)自己的需求準備即可。
差異比較分類
這不是比較關(guān)鍵的,只能兩兩比較。
my_comparisons <- list( c("non_metastatic", "weakly_metastatic"),
c("non_metastatic", "metastatic"),
c("weakly_metastatic", "metastatic") )
> my_comparisons
[[1]]
[1] "non_metastatic" "weakly_metastatic"
[[2]]
[1] "non_metastatic" "metastatic"
[[3]]
[1] "weakly_metastatic" "metastatic"
繪圖
基礎(chǔ)圖形
ggviolin(df, "status_metpot", "emt_score", fill = "status_metpot")

更改顏色
ggviolin(df, "status_metpot", "emt_score", fill = "status_metpot",
palette = c("#00AFBB", "#E7B800", "#FC4E07"))

添加柱子
ggviolin(df, "status_metpot", "emt_score", fill = "status_metpot",
+ palette = c("#00AFBB", "#E7B800", "#FC4E07"),add = "boxplot", add.params = list(fill = "white"))

柱子顏色可以更改,
add.params = list(fill = "white")。
添加差異比較標識
使用stat_compare_means()函數(shù)進行差異比較。
stat_compare_means(comparisons = my_comparisons,method="wilcox")

使用“ * ” 標記
“ * ”號標記是比較常用的標記,我只需要在更改顯示即可label = "p.signif"。
stat_compare_means(comparisons = my_comparisons,method="wilcox", label = "p.signif")

-
abel = "p.signif": 顯示**標記 -
size=7: 更改顯示大小 -
method: 比較方法
添加線條參數(shù)
geom_hline(yintercept=0, linetype="dashed", color = "red")
完整代碼
my_comparisons <- list( c("non_metastatic", "weakly_metastatic"),
c("non_metastatic", "metastatic"),
c("weakly_metastatic", "metastatic") )
ggviolin(df, "status_metpot", "emt_score", fill = "status_metpot",
palette = c("#00AFBB", "#E7B800", "#FC4E07"),
add = "boxplot", add.params = list(fill = "white"),xlab="Metastatic Potential")+
stat_compare_means(comparisons = my_comparisons,method="wilcox", label = "p.signif", ## label = "p.signif" 顯示**標記
hide.ns=TRUE,size=7)+ ## size 顯示大小
geom_hline(yintercept=0, linetype="dashed", color = "red")

往期文章:
1. 最全WGCNA教程(替換數(shù)據(jù)即可出全部結(jié)果與圖形)
2. 精美圖形繪制教程
小杜的生信筆記 ,主要發(fā)表或收錄生物信息學的教程,以及基于R的分析和可視化(包括數(shù)據(jù)分析,圖形繪制等);分享感興趣的文獻和學習資料!!
