有时候什么都不想做,这个时候突然看到了一个渐变色的火山图,想着看看能不能画出一样的效果,看到的效果图为图1;随后自己写代码做出来了一个(定义了颜色,刚好一个文章中需要)

285639812718647883.jpg
图1
CODE如下
rm(list = ls())
options(stringsAsFactors = F)
# Load required R packages
library(ggplot2)
library(clusterProfiler)
library(org.Hs.eg.db)
# Read the data
# Adjust the file path as needed
data <- read.delim("GSE123861.top.table (1).tsv")
# Calculate -log10(pvalue)
data$log_pvalue <- -log10(data$pvalue)
# Mark significance
data$sig <- ifelse(data$padj < 0.05 & abs(data$log2FoldChange) > 1, "Significant", "Not Significant")
# Create volcano plot with gradient colors
p <- ggplot(data, aes(x = log2FoldChange, y = log_pvalue)) +
# Plot non-significant genes in gray
geom_point(color = "gray", alpha = 0.5, size = 2) +
# Plot significant genes with gradient color based on log2FoldChange
geom_point(data = data[data$sig == "Significant", ], aes(color = log2FoldChange), alpha = 0.5, size = 2) +
scale_color_gradient2(low = "#4a7da8", mid = "white", high = "#b2446b", midpoint = 0) +
# Add threshold lines at log2FoldChange = -1 and 1
geom_vline(xintercept = c(-1, 1), linetype = "dashed", color = "black") +
theme_minimal() +
labs(title = "Volcano Plot", x = "Log2 Fold Change", y = "-Log10 P-value")
# Display the volcano plot
print(p)