關(guān)于小提琴圖和柱狀圖的繪制教程很多,在我們前面的教程中也推送過(guò),大家感興趣的可以去看一下鲜棠。今天,我們繼續(xù)小提琴+柱狀圖的組合圖培慌,且繪制出差異標(biāo)識(shí)豁陆。
繪圖
數(shù)據(jù)準(zhǔn)備
library(ggpubr)
df <- read.csv("20230306.input.csv",header = T)
head(df)
數(shù)據(jù)根據(jù)自己的需求準(zhǔn)備即可。
差異比較分類(lèi)
這不是比較關(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")
馅而。添加差異比較標(biāo)識(shí)
使用stat_compare_means()
函數(shù)進(jìn)行差異比較祥诽。
stat_compare_means(comparisons = my_comparisons,method="wilcox")
使用“ * ” 標(biāo)記
“ * ”號(hào)標(biāo)記是比較常用的標(biāo)記,我只需要在更改顯示即可label = "p.signif"
用爪。
stat_compare_means(comparisons = my_comparisons,method="wilcox", label = "p.signif")
-
abel = "p.signif"
: 顯示**標(biāo)記 -
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" 顯示**標(biāo)記
hide.ns=TRUE,size=7)+ ## size 顯示大小
geom_hline(yintercept=0, linetype="dashed", color = "red")
往期文章:
1. 最全WGCNA教程(替換數(shù)據(jù)即可出全部結(jié)果與圖形)
2. 精美圖形繪制教程
小杜的生信筆記 原押,主要發(fā)表或收錄生物信息學(xué)的教程,以及基于R的分析和可視化(包括數(shù)據(jù)分析偎血,圖形繪制等)诸衔;分享感興趣的文獻(xiàn)和學(xué)習(xí)資料!!