绘出后的图如下:
所需的数据文件格式如下:
####下面是有关代码
library(ggpubr)
inputFile="input.txt"
outFile="vioplot.pdf"
#读取
rt=read.table(inputFile,header=T,sep="\t",check.names=F)
x=colnames(rt)[2]
y=colnames(rt)[3]
colnames(rt)=c("id","Type","Expression")
#s设置比较组
group=levels(factor(rt$Type))
rt$Type=factor(rt$Type, levels=group)
comp=combn(group,2)
my_comparisons=list()
for(i in 1:ncol(comp)){my_comparisons[[i]]<-comp[,i]}
#绘制
pdf(file=outFile, width=6, height=5)
ggviolin(rt, x="Type", y="Expression", fill = "Type",
xlab=x, ylab=y,
legend.title=x,
add = "boxplot", add.params = list(fill="white"))+
stat_compare_means(comparisons = my_comparisons)
dev.off()