差异表达基因火山图(ggplot函数)

1. 读入数据

差异表达基因来自limma分析结果。

# read the file
data <- read.csv("diff_expr_genes.csv",row.names=1)
# sorting
data = diff_genes[order(diff_genes$adj.P.Val),]
head(data)
class(data)

colnames(data)
dim(data)

# 如果之前保存的是R对象
save(nrDEG_limma_voom, file = 'diff_expr_genes')
load('diff_expr_genes')
data <- nrDEG_limma_voom

2. ggplot作火山图

# 颜色设定
data$color <- ifelse(data$adj.P.Val<0.05 & abs(data$logFC)>= 1,
                     ifelse(data$logFC > 1,'red','blue'),'gray')

#install.packages("ggplot2")
#install.packages("ggrepel")

# 导入包
library(ggplot2)
library(ggrepel) # labels 不重叠

#tiff(filename = "volcano.tif",width = 720, height = 720)
rownames(data) <- data$symbol

# 设定要标出的基因名
data$sign <- ifelse(data$adj.P.Val < 1e-10 & abs(data$logFC) >4,
                    rownames(data),NA)

p <- ggplot(data, aes(logFC, -log10(adj.P.Val), col = color)) +
  geom_point() +
  theme_bw() +
  scale_color_manual(values = color) +
  labs(x="log2 (fold change)",y="-log10 (q-value)") +
  geom_hline(yintercept = -log10(0.05), lty=4,col="grey",lwd=0.6) +
  geom_vline(xintercept = c(-1, 1), lty=4,col="grey",lwd=0.6) +
  theme(legend.position = "none",
        panel.grid=element_blank(),
        axis.title = element_text(size = 18),
        axis.text = element_text(size = 14)) +
  geom_text_repel(aes(label = sign), size = 3)
print(p)

#dev.off()
# ggsave保存
ggsave("ggsave_volcano.tif",dpi=100,plot=p,device = 'tiff')

#device:    "eps", "ps", "tex" (pictex), "pdf", "jpeg", 
#"tiff", "png", "bmp","svg" or "wmf" (windows only)


 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值