当前位置:网站首页>生信常用分析图形绘制02 -- 解锁火山图真谛!
生信常用分析图形绘制02 -- 解锁火山图真谛!
2022-07-24 17:31:00 【夏雨秋风】

有了R语言的基础,以及ggplot2绘图基础,我们的「生信常用分析图形」的绘制就可以提上日程了!本系列,师兄就开始带着大家一起学习如何用R语言绘制我们自己的各种分析图吧!
*由于本系列的所有分析代码均为师兄细心整理和详细注释而成的!欢迎点赞、收藏、转发!
您的支持是我持续更新的最大动力!
*
系列内容包括:
各种类型的热图你学会了吗? 普通热图 环形热图
解锁火山图真谛! plot函数就能画火山图? 高级函数绘制火山图--ggplot2、ggpurb
经典富集分析及气泡图、柱状图绘制 气泡图绘制 柱状图绘制
富集分析圈图 富集分析弦图 绘制一张可以打动审稿人的桑基图 生存分析 -- KM曲线图 基础PCA图 云雨图 韦恩图 环形互作网络图 相互作用网络图 聚类树美化 富集分析气泡图进阶版 mantel test相关性图 词云图 瀑布图 森林图 曼哈顿图 哑铃图 三线表 嵌套圈图 列线图 蜂群图 箱线图+贝塞尔曲线 矩阵散点图 等等,想到再继续补充!!!
本期火山图效果展示

R自带函数plot就能画火山图?
##############
data <- read.csv("DEG.csv",row.names = 1)
color <- rep("#999999",nrow(data))
color[data$pvalue <0.05 & data$log2FoldChange > 1] <- "#FC4E07"
color[data$pvalue <0.05 & data$log2FoldChange < -1] <- "#00AFBB"
par(oma = c(0,2,0,0))
plot(data$log2FoldChange,-log10(data$pvalue),pch = 16,cex = 0.5,
xlim = c(-4,4), ylim = c(0,32), col = color, frame.plot = F,
xlab = "log2FC", ylab = "-log10(Pvalue)", cex.axis = 1, cex.lab = 1.3)
# 添加参考线:
abline(h = -log10(0.05),lwd = 2, lty = 3) # lwd设置线的宽度,lty设置线的类型;
abline(v = c(-1,1),lwd = 2, lty = 3) # lwd设置线的宽度,lty设置线的类型;
# 添加图例
legend(x = 3, y = 32, legend = c("Up","Normal","Down"),
bty = "n", # 去除边框
pch = 19,cex = 1, # 设置点的样式和大小
x.intersp = 0.3, # 设置字与点之间的距离;
y.intersp = 0.3, # 设置点与点的高度差,相当于行距;
col = c("#FC4E07","#999999","#00AFBB"))
# 添加标签:
color = c()
color[which(data[1:10,]$regulate == "Up")] = "#FC4E07"
color[which(data[1:10,]$regulate != "Up")] = "#00AFBB"
text(data$log2FoldChange[1:10],-log10(data$pvalue)[1:10],
labels = data$row[1:10],
adj = c(0,1.5),
cex = 0.6,
col = color)
将上述代码封装成函数,以后调用,就可以一键出图:
# 包装函数:
# 调整1: xlim和ylim得去掉
# 调整2: 修改图例的位置
plotVoc <- function(data){
color <- rep("#999999",nrow(data))
color[data$pvalue <0.05 & data$log2FoldChange > 1] <- "#FC4E07"
color[data$pvalue <0.05 & data$log2FoldChange < -1] <- "#00AFBB"
par(oma = c(0,2,0,0))
plot(data$log2FoldChange,-log10(data$pvalue),pch = 16,cex = 0.5,
col = color, frame.plot = F,
xlab = "log2FC", ylab = "-log10(Pvalue)", cex.axis = 1, cex.lab = 1.3)
# 添加参考线:
abline(h = -log10(0.05),lwd = 2, lty = 3) # lwd设置线的宽度,lty设置线的类型;
abline(v = c(-1,1),lwd = 2, lty = 3) # lwd设置线的宽度,lty设置线的类型;
# 添加图例
legend(x = 3, y = max(-log10(data$pvalue)), legend = c("Up","Normal","Down"),
bty = "n", # 去除边框
pch = 19,cex = 1, # 设置点的样式和大小
x.intersp = 0.3, # 设置字与点之间的距离;
y.intersp = 0.3, # 设置点与点的高度差,相当于行距;
col = c("#999999", "#FC4E07","#00AFBB"))
# 添加标签:
color = c()
color[which(data[1:10,]$regulate == "Up")] = "#FC4E07"
color[which(data[1:10,]$regulate != "Up")] = "#00AFBB"
text(data$log2FoldChange[1:10],-log10(data$pvalue)[1:10],
labels = data$row[1:10],
adj = c(0,1.5),
cex = 0.6,
col = color)
}
data <- read.csv("DEG2.csv",row.names = 1)
plotVoc(data)

高级函数绘制火山图--ggplot2、ggpurb
使用ggplot2绘制:
library(ggplot2)
data <- read.csv("DEG.csv",row.names = 1)
#################
# ggplot2绘制火山图
data$label <- c(rownames(data)[1:10],rep(NA,nrow(data) - 10))
ggplot(data,aes(log2FoldChange,-log10(pvalue),color = regulate)) +
xlab("log2FC") +
geom_point(size = 0.6) +
scale_color_manual(values=c("#00AFBB","#999999","#FC4E07")) +
geom_vline(xintercept = c(-1,1), linetype ="dashed") +
geom_hline(yintercept = -log10(0.05), linetype ="dashed") +
theme(title = element_text(size = 15), text = element_text(size = 15)) +
theme_classic() +
geom_text(aes(label = label),size = 3, vjust = 1,hjust = -0.1)
使用ggpurb的scatter函数也可以画:
#############
# 使用ggpurb绘制火山图:
library(ggpubr)
data$pvalue <- -log10(data$pvalue)
ggscatter(data,
x = "log2FoldChange",
y = "pvalue",
ylab="-log10(P.value)",
size=0.6,
color = "regulate",
label = rownames(data),
label.select = rownames(data)[1:10],
repel = T,
palette = c("#00AFBB", "#999999", "#FC4E07")) +
geom_hline(yintercept = 1.30,linetype ="dashed") +
geom_vline(xintercept = c(-1,1),linetype ="dashed")

往期优秀图形目录
复制即可
往期文章
边栏推荐
- Can Lu Zhengyao hide from the live broadcast room dominated by Luo min?
- Safety: how to provide more protection for pedestrians
- It's time to consider slimming down your app
- Mobile robot (IV) four axis aircraft
- AI opportunities for operators: expand new tracks with large models
- [spoken English] 01 - Introduction to atom
- EF core data filtering
- Reptiles and counter crawls: an endless battle
- 还在用Xshell?你out了,推荐一个更现代的终端连接工具!
- 2022 Asia International Internet of things exhibition
猜你喜欢

图像像素的逻辑操作

2022 牛客暑期多校 K - Link with Bracket Sequence I(线性dp)

Array double pointer - deliberate practice

Internship report 1 - face 3D reconstruction method

二维卷积——torch.nn.conv2d的使用

How the computer accesses the Internet (IV) LAN and server response

Method of querying comma separated strings in a field by MySQL

CDN(Content Delivery Network)内容分发网络从入门到与实战

电脑监控是真的吗?4个实验一探究竟

实习报告1——人脸三维重建方法
随机推荐
CDN(Content Delivery Network)内容分发网络从入门到与实战
Iqiyi Tiktok reconciled, Weibo lying gun?
电脑监控是真的吗?4个实验一探究竟
Today, I met a 38K from Tencent, which let me see the ceiling of the foundation
PAT甲级——A + B 格式
别再到处乱放配置文件了!试试我司使用 7 年的这套解决方案,稳的一秕
2022 Yangtze River Delta industrial automation exhibition will be held in Nanjing International Exhibition Center in October
Ipaylinks, a cross-border payment integration service, won the 3A Asia Award of treasury
2022年最新浙江建筑安全员模拟题库及答案
Still using xshell? You are out, recommend a more modern terminal connection tool!
mysql 查询某字段中以逗号分隔的字符串的方法
Two dimensional convolution -- use of torch.nn.conv2d
I'll teach you how to use NPs to build intranet penetration services. When you go out, you can easily connect your lightweight notebook to your home game console to play remotely
Extension of ES6 function
Canvas from getting started to persuading friends to give up (graphic version)
Js实现继承的六种方式
图像像素的逻辑操作
Atcoder beginer 202 e - count descendants (heuristic merge on heavy chain split tree for offline query)
[how to optimize her] teach you how to locate unreasonable SQL? And optimize her~~~
C语言编程训练题目:左旋字符串中的k个字符、小乐乐与欧几里得、打印箭型图案、公务员面试、杨树矩阵