每日R语言绘图(6)——boxplotDiff差异箱型图

绘出后的图如下:


所需的数据文件格式如下:




####下面是有关代码

library(ggpubr) #引用包

inputFile="input.txt"      #输入文件

outFile="boxplot.pdf"      #输出文件

#读取输入文件,并对输入文件整理

rt=read.table(inputFile,sep="\t",header=T,check.names=F)

x=colnames(rt)[2]

y=colnames(rt)[3]

colnames(rt)=c("id","Type","Expression")

#设置比较租

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]}

#绘制boxplot

boxplot=ggboxplot(rt, x="Type", y="Expression", color="Type",

          xlab=x,

          ylab=y,

          legend.title=x,

          palette = c("blue","red"),

          add = "jitter")+

    stat_compare_means(comparisons = my_comparisons)

#输出图片

pdf(file=outFile,width=5,height=4.5)

print(boxplot)

dev.off()

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容