直接上代码了
例样
> head(mydata)
log2FoldChange padj gene_name Condition color label
1 0.6606656 0.052406355 gene_1 normal gray
2 2.7241968 0.015946453 gene_2 normal gray
3 -6.8942728 0.009979404 gene_3 down green
4 -1.6221782 0.009072244 gene_4 down green
5 -0.2304992 0.049112292 gene_5 normal gray
6 -2.4364508 0.050120772 gene_6 normal gray
代码
library(ggplot2)
library(ggrepel) ##该包能够解决散点图样品标签重叠的问题,方便筛选样品
ggplot(data=mydata, aes(x=log2FoldChange, y=-log10(padj))) +
geom_point(aes(color = Condition), alpha = 0.8, size = 1) +
scale_color_manual(values = c('blue2', 'gray30', 'red2')) +
labs(x="log2 fold change", y="-log10 padj", title="XXvsXX") +
theme(panel.grid = element_blank(), panel.background = element_rect(color = 'black', fill = 'transparent'), legend.position = c(0.08, 0.92)) +
theme(legend.title = element_blank(), legend.key = element_rect(fill = 'transparent'), legend.background = element_rect(fill = 'transparent')) +
geom_hline(yintercept=-log10(0.01),linetype=4, color = 'gray', size = 0.25) +
geom_vline(xintercept=c(-1,1),linetype=4, color = 'gray', size = 0.25) +
geom_text_repel(data=mydata,aes(x=log2FoldChange, y=-log10(padj),label=label),size=2) +
xlim(-15,15)+##控制横坐标长度
theme(plot.title = element_text(hjust = 0.5,size = 20, face = "bold")) ##添加居中的标题U
结果
火山图结果













网友评论