R语言可视化:火山图绘制

Posted bioinfomics

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了R语言可视化:火山图绘制相关的知识,希望对你有一定的参考价值。


R语言可视化(十一):火山图绘制
This browser does not support music or audio playback. Please play it in WeChat or another browser. R语言可视化(十一):火山图绘制

R语言可视化(十一):火山图绘制

11.火山图绘制


清除当前环境中的变量

rm(list=ls())

设置工作目录

setwd("C:/Users/Dell/Desktop/R_Plots/11volcano/")

读取示例数据

data <- read.table("demo_volcano.txt",header = T,
check.names = F,row.names = 1,sep=" ")

# 查看示例数据
head(data)
## LOG_count WT0_count LOG_rpkm WT0_rpkm log2_Ratio(WT0/LOG)
## Unigene0000003 17243 17525 931.5677 942.4515 0.01675776
## Unigene0000004 65 101 4.1156 6.3657 0.62921640
## Unigene0000005 909 984 36.8859 39.7458 0.10773298
## Unigene0000006 1376 1082 74.7026 58.4714 -0.35342732
## Unigene0000007 121 73 15.6800 9.4163 -0.73569337
## Unigene0000008 221 308 13.1401 18.2287 0.47223542
## Pvalue FDR significant
## Unigene0000003 0.5149484880 0.6733042200 no
## Unigene0000004 0.0066439000 0.0178825370 no
## Unigene0000005 0.1259729560 0.2246500490 no
## Unigene0000006 0.0000000117 0.0000000686 no
## Unigene0000007 0.0007419290 0.0024460860 no
## Unigene0000008 0.0003037820 0.0010721500 no

base plot函数绘制火山图

attach(data)
# 基础火山图
plot(x=`log2_Ratio(WT0/LOG)`,y=-1*log10(FDR))

R语言可视化(十一):火山图绘制

# 添加颜色和标题
plot(x=`log2_Ratio(WT0/LOG)`,y=-1*log10(FDR),
type = "p", pch=20, col=significant,
main="Volcano plot",
xlab="log2(FC)",ylab="-log10(FDR)")

R语言可视化(十一):火山图绘制

# 添加水平线和垂直线
abline(v=c(-1,1),lty=2,lwd = 2,col="red")
abline(h=-log10(0.05),lty=2,lwd=2,col="blue"
# 添加图例
legend("topright", inset = 0.01, title = "Significant", c("yes","no"),
pch=c(16,16),col = c("red","black"))

R语言可视化(十一):火山图绘制

# 添加gene注释信息
gene_selected <- c("Unigene0034898","Unigene0038455","Unigene0003997",
"Unigene0026444","Unigene0039482","Unigene0028163"
)
data_selected <- data[gene_selected,]
text(x=data_selected$`log2_Ratio(WT0/LOG)`,y=-1*log10(data_selected$FDR),
labels = rownames(data_selected),col="red",adj = 0.5)
detach(data)

R语言可视化(十一):火山图绘制

ggplot2包绘制火山图

library(ggplot2)
head(data)
## LOG_count WT0_count LOG_rpkm WT0_rpkm log2_Ratio(WT0/LOG)
## Unigene0000003 17243 17525 931.5677 942.4515 0.01675776
## Unigene0000004 65 101 4.1156 6.3657 0.62921640
## Unigene0000005 909 984 36.8859 39.7458 0.10773298
## Unigene0000006 1376 1082 74.7026 58.4714 -0.35342732
## Unigene0000007 121 73 15.6800 9.4163 -0.73569337
## Unigene0000008 221 308 13.1401 18.2287 0.47223542
## Pvalue FDR significant
## Unigene0000003 0.5149484880 0.6733042200 no
## Unigene0000004 0.0066439000 0.0178825370 no
## Unigene0000005 0.1259729560 0.2246500490 no
## Unigene0000006 0.0000000117 0.0000000686 no
## Unigene0000007 0.0007419290 0.0024460860 no
## Unigene0000008 0.0003037820 0.0010721500 no

# 基础火山图
ggplot(data,aes(`log2_Ratio(WT0/LOG)`,-log10(FDR))) + geom_point()

R语言可视化(十一):火山图绘制

# 添加颜色和标题
ggplot(data,aes(`log2_Ratio(WT0/LOG)`,-log10(FDR),color=significant)) +
geom_point() +
labs(title="Volcano plot",x=expression(log[2](FC)), y=expression(-log[10](FDR)))

R语言可视化(十一):火山图绘制

# 更改颜色,主题,添加水平线和垂直线,去掉网格线
p <- ggplot(data,aes(`log2_Ratio(WT0/LOG)`,-log10(FDR),color=significant)) +
geom_point() + theme_bw() +
labs(title="Volcano plot",x=expression(log[2](FC)), y=expression(-log[10](FDR))) +
scale_color_manual(values = c("blue","red")) +
geom_vline(xintercept=-1, linetype=2, colour="gray30") +
geom_vline(xintercept=1, linetype=2, colour="gray30") +
geom_hline(yintercept=-log(0.05), linetype=2, colour="gray30") +
theme(plot.title = element_text(hjust = 0.5)) +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank())
p

R语言可视化(十一):火山图绘制

# 添加基因注释信息
library(ggrepel)
p + geom_text_repel(data=data_selected,
aes(label=rownames(data_selected)))

R语言可视化(十一):火山图绘制

p + geom_label_repel(data=data_selected,
aes(label=rownames(data_selected)))

R语言可视化(十一):火山图绘制

ggpubr包绘制火山图

library(ggpubr)
data$FDR <- -log10(data$FDR)
data$FC <- data$`log2_Ratio(WT0/LOG)`
head(data)
## LOG_count WT0_count LOG_rpkm WT0_rpkm log2_Ratio(WT0/LOG)
## Unigene0000003 17243 17525 931.5677 942.4515 0.01675776
## Unigene0000004 65 101 4.1156 6.3657 0.62921640
## Unigene0000005 909 984 36.8859 39.7458 0.10773298
## Unigene0000006 1376 1082 74.7026 58.4714 -0.35342732
## Unigene0000007 121 73 15.6800 9.4163 -0.73569337
## Unigene0000008 221 308 13.1401 18.2287 0.47223542
## Pvalue FDR significant FC
## Unigene0000003 0.5149484880 0.1717887 no 0.01675776
## Unigene0000004 0.0066439000 1.7475709 no 0.62921640
## Unigene0000005 0.1259729560 0.6484935 no 0.10773298
## Unigene0000006 0.0000000117 7.1636759 no -0.35342732
## Unigene0000007 0.0007419290 2.6115283 no -0.73569337
## Unigene0000008 0.0003037820 2.9697445 no 0.47223542

# 基础火山图
ggscatter(data,x="FC",y="FDR")

R语言可视化(十一):火山图绘制

# 添加颜色,标题,坐标轴标签
ggscatter(data,x="FC",y="FDR",size = 1.5,
color = "significant", palette = c("#BBBBBB","#CC0000"),
title = "Volcano plot",xlab = "log2(FC)",ylab = "-log10(FDR)")

R语言可视化(十一):火山图绘制

# 添加水平线和垂直线,标题居中
ggscatter(data,x="FC",y="FDR",size = 1.5,
color = "significant", palette = c("#BBBBBB","#CC0000"),
title = "Volcano plot",xlab = "log2(FC)",ylab = "-log10(FDR)") +
geom_vline(xintercept=c(-1,1), linetype=2, colour="gray30") +
geom_hline(yintercept=-log(0.05), linetype=2, colour="gray30") +
theme(plot.title = element_text(hjust = 0.5))

R语言可视化(十一):火山图绘制

sessionInfo()
## R version 3.6.0 (2019-04-26)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 18363)
##
## Matrix products: default
##
## locale:
## [1] LC_COLLATE=Chinese (Simplified)_China.936
## [2] LC_CTYPE=Chinese (Simplified)_China.936
## [3] LC_MONETARY=Chinese (Simplified)_China.936
## [4] LC_NUMERIC=C
## [5] LC_TIME=Chinese (Simplified)_China.936
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] ggpubr_0.2.1 magrittr_1.5 ggrepel_0.8.1 ggplot2_3.2.0
##
## loaded via a namespace (and not attached):
## [1] Rcpp_1.0.5 knitr_1.23 tidyselect_0.2.5 munsell_0.5.0
## [5] colorspace_1.4-1 R6_2.4.0 rlang_0.4.7 stringr_1.4.0
## [9] dplyr_0.8.3 tools_3.6.0 grid_3.6.0 gtable_0.3.0
## [13] xfun_0.8 withr_2.1.2 htmltools_0.3.6 yaml_2.2.0
## [17] lazyeval_0.2.2 digest_0.6.20 assertthat_0.2.1 tibble_2.1.3
## [21] ggsignif_0.5.0 crayon_1.3.4 purrr_0.3.2 glue_1.3.1
## [25] evaluate_0.14 rmarkdown_1.13 labeling_0.3 stringi_1.4.3
## [29] compiler_3.6.0 pillar_1.4.2 scales_1.0.0 pkgconfig_2.0.2


R语言可视化(十一):火山图绘制

END


R语言可视化(十一):火山图绘制

R语言可视化(十一):火山图绘制
R语言可视化(十一):火山图绘制


更多精彩推荐,请关注我们
R语言可视化(十一):火山图绘制
把时间交给阅读


您点的每个赞,我都认真当成了喜欢

以上是关于R语言可视化:火山图绘制的主要内容,如果未能解决你的问题,请参考以下文章

R语言绘制火山图(volcano plot)实战:为差异表达基因(DEGs)添加颜色基于显著性阈值进行点的颜色美化为选定基因添加标签

一起来学习如何使用R语言绘制热图

【R】热图绘制

数据可视化应用绘制森林图(附Python和R语言代码)

数据可视化应用绘制圆角条形图(附R语言代码)

数据可视化应用绘制和弦图(附Python和R语言代码)