简述:
小提琴图 (Violin Plot) 用于显示数据分布及其概率密度。这种图表结合了箱形图和密度图的特征,主要用来显示数据的分布形状。
中间的黑色粗条表示四分位数范围,从其延伸的细黑线代表数据范围,两端为最大值和最小值,而白点则为中位数。
箱形图在数据显示方面受到限制,简单的设计往往隐藏了有关数据分布的重要细节。例如使用箱形图时,我们不能了解数据分布是双模还是多模。虽然小提琴图可以显示更多详情,但它们也可能包含较多干扰信息。
小提琴图
ggpurb包可以制作小提琴图,做图示例如下:
示例
需要输入的数据形式如下:
数据格式
绘图代码:
library(ggpubr)
#转化为因子方便排序
cluster$Subtype=factor(cluster$Subtype, levels=c("Immunity_L","Immunity_M","Immunity_H"))
#定义组间比较方式
my_comparisons=list(c("Immunity_L","Immunity_M"),c("Immunity_M","Immunity_H"),c("Immunity_H","Immunity_L"))
#绘图
ggviolin(cluster, x="Subtype", y="TumorPurity", fill = "Subtype",
palette = c("green", "blue", "red"), ylab='Tumor purity', xlab="Subtype",
add = "boxplot", add.params = list(fill="white"))+
stat_compare_means(comparisons = my_comparisons,symnum.args=list(cutpoints = c(0, 0.001, 0.01, 0.05, 1), symbols = c("***", "**", "*", "ns")),label = "p.signif")
#仅仅写+stat_compare_means()显示默认方式p值及统计学方法