1. rm(list = ls())
  2. load(file = "step1output.Rdata")
  3. load(file = "step4output.Rdata")
  4. #1.火山图----
  5. library(dplyr)
  6. library(ggplot2)
  7. dat = deg[!duplicated(deg$symbol),]
  8. p <- ggplot(data = dat,
  9. aes(x = logFC,
  10. y = -log10(P.Value))) +
  11. geom_point(alpha=0.4, size=3.5,
  12. aes(color=change)) +
  13. ylab("-log10(Pvalue)")+
  14. scale_color_manual(values=c("blue", "grey","red"))+
  15. geom_vline(xintercept=c(-logFC_t,logFC_t), ##竖线
  16. lty=4,col="black",lwd=0.8) +
  17. geom_hline(yintercept = -log10(P.Value_t), ##横线
  18. lty=4,col="black",lwd=0.8) +
  19. theme_bw()
  20. p
  21. for_label <- dat%>%
  22. filter(symbol %in% c("HADHA","LRRFIP1"))
  23. volcano_plot <- p +
  24. geom_point(size = 3, shape = 1, data = for_label) +
  25. ggrepel::geom_label_repel( ##加label的图层,加标签的图层
  26. aes(label = symbol),
  27. data = for_label,
  28. color="black"
  29. )
  30. volcano_plot
  31. ggsave(plot = volcano_plot,filename = paste0(gse_number,"_volcano.png"))

2.差异基因热图——

  1. load(file = 'step2output.Rdata')

行名替换

  1. exp = exp[dat$probe_id,]
  2. rownames(exp) = dat$symbol
  3. if(F){
  4. #全部差异基因
  5. cg = dat$symbol[dat$change !="stable"]
  6. length(cg)
  7. }else{
  8. #取前10上调和前10下调
  9. x=dat$logFC[dat$change !="stable"]
  10. names(x)=dat$symbol[dat$change !="stable"]
  11. cg=names(c(head(sort(x),10),tail(sort(x),10)))
  12. length(cg)
  13. }
  14. n=exp[cg,]
  15. dim(n)

差异基因热图

  1. library(pheatmap)
  2. annotation_col=data.frame(group=Group)
  3. rownames(annotation_col)=colnames(n)
  4. heatmap_plot <- pheatmap(n,show_colnames =F,
  5. scale = "row",
  6. #cluster_cols = F,
  7. annotation_col=annotation_col,
  8. breaks = seq(-3,3,length.out = 100)
  9. )
  10. heatmap_plot
  11. ggsave(heatmap_plot,filename = paste0(gse_number,"_heatmap.png"))

感兴趣基因的箱线图

  1. g = c(head(cg,3),tail(cg,3))
  2. library(tidyr)
  3. library(tibble)
  4. library(dplyr)
  5. dat = t(exp[g,]) %>%
  6. as.data.frame() %>%
  7. rownames_to_column() %>%
  8. mutate(group = Group)
  9. pdat = dat%>%
  10. pivot_longer(cols = 2:(ncol(dat)-1),
  11. names_to = "gene",
  12. values_to = "count")
  13. pdat$gene = factor(pdat$gene,levels = cg,ordered = T)
  14. pdat$change = ifelse(pdat$gene %in% head(cg,10),"down","up")
  15. library(ggplot2)
  16. library(paletteer)
  17. box_plot = ggplot(pdat,aes(gene,count))+
  18. geom_boxplot(aes(fill = group))+
  19. #scale_fill_manual(values = c("blue","red"))+
  20. scale_fill_paletteer_d("basetheme::minimal")+
  21. geom_jitter()+
  22. theme_bw()+
  23. facet_wrap(~change,scales = "free")
  24. box_plot
  25. ggsave(box_plot,filename = paste0(gse_number,"_boxplot.png"))
  26. # 4.感兴趣基因的相关性----
  27. library(corrplot)
  28. M = cor(t(exp[g,])) ##默认求列的相关性
  29. pheatmap(M)
  30. my_color = rev(paletteer_d("RColorBrewer::RdYlBu"))
  31. my_color = colorRampPalette(my_color)(10)
  32. corrplot(M, type="upper",
  33. method="pie",
  34. order="hclust",
  35. col=my_color,
  36. tl.col="black",
  37. tl.srt=45)
  38. library(cowplot)
  39. cor_plot <- recordPlot()

感兴趣基因的相关性

  1. # 4.感兴趣基因的相关性----
  2. library(corrplot)
  3. M = cor(t(exp[g,])) ##默认求列的相关性
  4. pheatmap(M)
  5. my_color = rev(paletteer_d("RColorBrewer::RdYlBu"))
  6. my_color = colorRampPalette(my_color)(10)
  7. corrplot(M, type="upper",
  8. method="pie",
  9. order="hclust",
  10. col=my_color,
  11. tl.col="black",
  12. tl.srt=45)
  13. library(cowplot)
  14. cor_plot <- recordPlot()

拼图

  1. load("pca_plot.Rdata")
  2. library(patchwork)
  3. library(ggplotify)
  4. (pca_plot + volcano_plot +as.ggplot(heatmap_plot))/box_plot
  5. plot_grid(cor_plot,heatmap_plot$gtable)