美文网首页
ggplot2箱线图

ggplot2箱线图

作者: 一只小脑斧 | 来源:发表于2022-04-21 12:38 被阅读0次
输入文件expClu

#把数据转换成ggplot2输入文件

data=melt(expClu, id.vars=c("geneCluster"))

colnames(data)=c("geneCluster", "Gene", "Expression")

data

#设置颜色

#bioCol=c("#0066FF","#FF9900","#FF0000","#6E568C","#7CC767","#223D6C","#D20A13","#FFD121","#088247","#11AA4D")

bioCol=c("#1c79c0","#0dd3ff","#0389ff")

#bioCol=c("#3be8b0","#ffb900","#fc636b")

bioCol=bioCol[1:length(levels(factor(data[,"geneCluster"])))]

#绘制箱线图

p=ggboxplot(data, x="Gene", y="Expression", color = "geneCluster",#根据分型结果定义颜色

    xlab="",#x轴名称

    ylab="Gene expression",#y轴名称

    legend.title="geneCluster",#图例标题

    palette = bioCol,#颜色

    width=1)

p=p+rotate_x_text(60)#x轴倾斜角度

#统计分析

p1=p+stat_compare_means(aes(group=geneCluster),

      symnum.args=list(cutpoints = c(0, 0.001, 0.01, 0.05, 1), symbols = c("***", "**", "*", " ")),

      label = "p.signif")

#输出箱线图

pdf(file="boxplot.pdf", width=9, height=6)

print(p1)#打印

dev.off()

相关文章

网友评论

      本文标题:ggplot2箱线图

      本文链接:https://www.haomeiwen.com/subject/sjpiertx.html