转录组学选择性剪切R学习与可视化

可变剪切分析(二)R画堆积柱状图

2020-08-11  本文已影响0人  大号在这里

一、数据准备与标准化

该数据是通过ASprofile软件对可变剪切的分析结果,具体分析过程参考上一篇文章

AS  N1  N2  N3  T1  T2  T3
XSKIP   1239    1156    1226    1302    1216    1256
XMSKIP  241 214 219 227 258 271
XMIR    28  22  29  28  29  24
XIR 324 359 352 402 437 403
XAE 610 678 715 731 794 728
TTS 19414   19342   19169   19707   19499   19486
TSS 20771   20718   20533   21181   20953   20982
SKIP    8569    8403    8225    8436    8190    8299
MSKIP   1927    1897    1775    1886    1773    1827
MIR 62  72  57  87  93  92
IR  557 605 549 648 697 657
AE  6325    6371    6142    6731    6617    6623

二、代码实现

#Stacking bar chart
#import data and modify it
phylum <- read.table('As_Result.stat', sep="\t", header=T, row.names=1)
phylum <- phylum/matrix(rep(colSums(phylum),nrow(phylum)), nrow = nrow(phylum), byrow = T)
phylum.ave <- apply(phylum, 1, FUN=mean)
phylum.2 <- cbind(phylum, phylum.ave)[order(-phylum.ave),]

#sum(phylum.2$phylum.ave[1:4]) 
#phylum.2 <- subset(phylum.2[1:12,], select=-phylum.ave) #check the summary of top 12 taxonomies
phylum.2 <- subset(phylum.2, select=-phylum.ave)
phylum.2 <- rbind(phylum.2)

#apply(phylum.2, 2, function(x){sum(x)})  #check the summary of each column
phylum.2 <- cbind(PhylumID=row.names(phylum.2), phylum.2)

#convert the data format
library(reshape2)
phylum.gg <- melt(phylum.2, id.vars="PhylumID", variable.name="SampleID", value.name="Percentage")

#sum(phypum.gg$Abundance) #check
#plot bar chart
library(ggplot2)
ggplot(phylum.gg, aes(SampleID, Percentage, fill=PhylumID)) +
  scale_fill_manual(values =  rev(c('#8085e8','#7cb5ec','#f15c80','#434348', '#90ed7d', '#f7a35c', '#da70d6', '#40e0d0', '#e4d354', '#3cb371', '#ff7f50', '#87cefa'))) +
  geom_bar(stat="identity",col='white') +
  theme(panel.grid = element_blank(), panel.background = element_rect(color = 'black', fill = 'transparent'), strip.text = element_text(size = 12)) +    ##设定分面标题字体大小
  theme(axis.text = element_text(size = 10), axis.title = element_text(size = 13), legend.title = element_blank(), legend.text = element_text(size = 9)) +
  guides(fill=guide_legend(reverse=F)) +
  scale_y_continuous(expand=c(0,0))

得到的图如下:


参考:
https://www.jianshu.com/p/fdbda4d45078
https://www.jianshu.com/p/0e67294b4408
上一篇下一篇

猜你喜欢

热点阅读