最后发布时间:2024-02-12 22:01:38

点击查看软件安装

library(tidyverse)
library(ggplot2)
library(ggrepel)
head(res)
DEG_all <- res %>% rownames_to_column("symbol") %>% 
  dplyr::select(symbol,logFC=log2FoldChange,Pvalue=padj)%>%
  mutate(direction = factor(ifelse(Pvalue < 0.01 & abs(logFC)>2,
                                  ifelse(logFC>1,"Up","Down"),
                                  "NS"),levels = c("Up","Down","NS"))) %>%
  na.omit()

ggplot(DEG_all,aes(x=logFC,y=-log10(Pvalue),colour=direction))+
  geom_point(alpha=0.6)  +
  scale_color_manual(values = c("#DC143C","#00008B","#808080"))+
  geom_text_repel(data=DEG_all %>%filter(Pvalue<0.01,abs(logFC)>9),
                  aes(label=symbol),
                  size=3,
                  segment.color="black",
                  show.legend = F)+
  xlab(expression(log[2]("Fold Change")))+
  ylab(expression(-log[10]("Adjusted P Value")))+
  ggtitle("Volcano Plot")+
  theme_bw()+
  theme(legend.title = element_blank(),
        plot.title = element_text(hjust = 0.5))+
  geom_vline(xintercept = c(-2,2),lty=2,col="black",lwd=0.6)+
  geom_hline(yintercept = -log10(0.01),lty=2,col="black",lwd=0.6)

DEG_all %>%filter(symbol %in% crc_mrna_deg$gene_id)

ggplot(DEG_all,aes(x=logFC,y=-log10(Pvalue),colour=direction))+
  geom_point(alpha=0.6)  +
  scale_color_manual(values = c("#DC143C","#00008B","#808080"))+
  geom_text_repel(data=DEG_all %>%filter(symbol %in% ppi_gene$gene_id),
                  aes(label=symbol),
                  size=3,
                  segment.color="black",
                  show.legend = F)+
  xlab(expression(log[2]("Fold Change")))+
  ylab(expression(-log[10]("Adjusted P Value")))+
  ggtitle("Volcano Plot")+
  theme_bw()+
  theme(legend.title = element_blank(),
        plot.title = element_text(hjust = 0.5))+
  geom_vline(xintercept = c(-2,2),lty=2,col="black",lwd=0.6)+
  geom_hline(yintercept = -log10(0.01),lty=2,col="black",lwd=0.6)

tiff(file="figures/crc_mRNA_Volcano.tiff",
     width = 35,height = 22,units = "cm",compression = "lzw",bg = "white",res=300)
ggplot(DEG_all,aes(x=logFC,y=-log10(Pvalue),colour=direction))+
  geom_point(alpha=0.6)  +
  scale_color_manual(values = c("red","green","#000000"))+
  xlab(expression(log[2]("Fold Change")))+
  ylab(expression(-log[10]("Adjusted P Value")))+
  ggtitle("mRNA Volcano")+
  theme_bw()+
  theme(legend.title = element_blank(),
        plot.title = element_text(hjust = 0.5,size = 20, face= "bold"),
        axis.title =  element_text(size=18),
        legend.text= element_text(size=15),
        aspect.ratio=1)+
  geom_vline(xintercept = c(-2,2),lty=2,col="black",lwd=0.6)+
  geom_hline(yintercept = -log10(0.01),lty=2,col="black",lwd=0.6) +
  ggsave("figures/mRNA_Volcano_square.png")

dev.off()