输入表达矩阵数据文件
library(ggplot2) library(reshape2) exprSet <- read.table(file = "COS_deseq_counts_normalized.txt", sep = "\t", header = T) group_list <- factor(c(rep("COS0",3),rep("COS1",3),rep("COS3",3),rep("COS6",3),rep("COS12",3)), levels = c("COS0", "COS1","COS3","COS6","COS12")) exprSet_L=melt(exprSet) colnames(exprSet_L)=c('Gene_ID','sample','value') exprSet_L$group=rep(group_list,each=nrow(exprSet)) #以sample作为x轴,group作为填充颜色 ggplot(exprSet,aes(x=sample,y=value,fill=group)) + geom_boxplot() #以group作为x轴,sample作为填充颜色 #ggplot(exprSet,aes(x=group,y=value,fill=sample)) + geom_boxplot() # 修改sample名称 exprSet_L$sample=paste(exprSet_L$group,exprSet_L$sample,sep="-") ggplot(exprSet_L,aes(x=sample,y=value,fill=group)) + geom_boxplot() # 离群点的大小 cvbox=ggplot(exprSet_L,aes(x=sample,y=value,fill=group))+geom_boxplot(outlier.size=0) #outlier.size=-1 ,点将彻底消失 # 修改x轴字符方向 cvbox+theme(axis.text.x=element_text(angle=90,vjust=0.5,hjust=1)) # 修改图例位置和主题 cvbox+theme_bw()+theme(axis.text.x=element_text(angle=90,vjust=0.5,hjust=1),legend.position="top") # geom_jitter():为图形设置抖动,防止相同点重叠 cvbox+theme_bw()+theme(axis.text.x=element_text(angle=90,vjust=0.5,hjust=1),legend.position="top") + geom_jitter()
Leave a Reply