相关性分析、PCA分析和火山图

样本相关性

anthersample_cor <- cor(anthertpm)
install.packages("ggcorrplot")
library(ggcorrplot)
ggcorrplot(anthersample_cor,outline.color = "white",ggtheme = ggplot2::theme_bw,colors = c("#6D9EC1", "white", "#E46726"),lab = T,title = "Corralation")
install.packages("pheatmap")
library(pheatmap)
pheatmap(anthersample_cor,cluster_rows = T,cluster_cols = T)
#anthertpm文件里面含有所有样本的TPM值

PCA

library(PCAtools)
anthertpm <- read.csv("E:\\热胁迫转录组\\RNAseq2\\TPM.csv",header=TRUE, stringsAsFactors=FALSE)
anthercoldata <- read.csv("E:\\热胁迫转录组\\RNAseq2\\coldata.csv",header = F,row.names = 1)
colnames(anthercoldata)<- "Treatment"
anthertpm<-anthertpm[,-1]
p <- PCAtools::pca(mat= anthertpm,metadata= anthercoldata,removeVar=0.1)
pca_loadings <- p[["loadings"]]
pca_rotated <- p[["rotated"]]
screeplot(p) 
biplot(p, x ='PC1',y ='PC2',colby = 'Treatment', legendPosition = 'top')
install.packages("scatterplot3d")
library(scatterplot3d)
library(scatterplot3d)
pca.data <- data.frame(sample = rownames(pca_rotated), Type=c(rep("control",3),rep("heat_stress",3)),pca_rotated)
s3d <- scatterplot3d(pca.data$PC1, pca.data$PC2, pca.data$PC3,color=c(rep("green",3),rep("red",3)),
                     pch = 16,angle=30,
                     cex.symbols = 2,
                     box=T,type="p",
                     main = "3D PCA Plot",
                     lty.hide=2,lty.grid = 2)
text(s3d$xyz.convert(pca.data[,3:5]+0.05), labels = pca.data[,1],
     cex= 0.8, col = "black",adj=c(0,-0.5))

火山图

library(ggplot2)
library(ggrepel)
huoshandat<-as.data.frame(huoshandata)
p <- ggplot(
  #数据、映射、颜色
  huoshandat,aes(x=log2FoldChange,y=-log10(padj),color=sig)) +
  geom_point() +
  scale_color_manual(values=c("#2f5688","#BBBBBB","#CC0000")) +  
  #辅助线
  geom_vline(xintercept=c(-1,1),lty=3,col="black",lwd=0.5) +  
  geom_hline(yintercept = -log10(0.05),lty=3,col="black",lwd=0.5) + 
  #坐标轴
  ylab('-log10 (p-adj)') +  
  xlab('log2 (FoldChange)') + 
  theme_bw()+ 
  #图例
  theme(plot.title =element_text(size=14,face = "bold"), 
        legend.position="right",
        legend.title = element_blank())   #调整坐标轴字号
p

火山图带标签

library(ggplot2)
library(ggrepel)
library(tibble)
anther_data<-as.data.frame(huoshandata)
anther_data<-rownames_to_column(anther_data,var = "rowname")
p <- ggplot(
  #数据、映射、颜色
  anther_data,aes(x=log2FoldChange,y=-log10(padj),color=sig)) +
  geom_point() +
  scale_color_manual(values=c("#2f5688","#BBBBBB","#CC0000")) +  
  #辅助线
  geom_vline(xintercept=c(-1,1),lty=3,col="black",lwd=0.5) +  
  geom_hline(yintercept = -log10(0.05),lty=3,col="black",lwd=0.5) + 
  #坐标轴
  ylab('-log10 (p-adj)') +  
  xlab('log2 (FoldChange)') + 
  theme_bw()+ 
  #图例
  geom_text_repel(data =  dplyr::filter(anther_data, abs(log2FoldChange) > 1 & -log10(padj) > 100),
                  max.overlaps = getOption("ggrepel.max.overlaps", default = 20),
                  aes(label = rowname,
                      color = sig),
                  size = 2)
p
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容