R语言可视化(十三)(气泡图绘制)
13. 富集气泡图绘制 清除当前环境中的变量
rm(list=ls())
设置工作目录
setwd("C:/Users/Dell/Desktop/R_Plots/13bubble/")
读取示例数据
data <- read.table("demo_bubble.tsv",header = T,
check.names = F,sep="\t")
head(data)
Pathway R0vsR3 All_UnigenePvalueQvalue
1 Plant hormone signal transduction70254 3.94000e-09 4.33e-07
2Phenylpropanoid biosynthesis49163 5.07000e-08 2.79e-06
3Phenylalanine metabolism38126 1.53000e-06 4.20e-05
4Plant-pathogen interaction45159 1.21000e-06 4.20e-05
5Flavonoid biosynthesis1122 5.86000e-05 1.29e-03
6Linoleic acid metabolism1124 1.58824e-04 2.50e-03
richFactor Pathway ID
10.2755906ko04075
20.3006135ko00940
30.3015873ko00360
40.2830189ko04626
50.5000000ko00941
60.4583333ko00591
基础symbols函数绘制气泡图
head(mtcars)
mpg cyl disphp dratwtqsec vs am gear carb
Mazda RX421.06160 110 3.90 2.620 16.460144
Mazda RX4 Wag21.06160 110 3.90 2.875 17.020144
Datsun 71022.8410893 3.85 2.320 18.611141
Hornet 4 Drive21.46258 110 3.08 3.215 19.441031
Hornet Sportabout 18.78360 175 3.15 3.440 17.020032
Valiant18.16225 105 2.76 3.460 20.221031attach(mtcars)
symbols(wt,mpg,circles=cyl,
inches=0.2,
bg=rainbow(7))
文章图片
image.png
# 添加文本标签
text(wt,mpg,labels = row.names(mtcars),cex=0.7,pos = 3,offset = 0.8)
文章图片
image.png
# 将圆圈换成正方形
symbols(wt,mpg,squares=cyl,
inches=0.3,
bg=rainbow(7))
detach(mtcars)
文章图片
image.png ggplot2包绘制富集气泡图
library(ggplot2)
head(data)
Pathway R0vsR3 All_UnigenePvalueQvalue
1 Plant hormone signal transduction70254 3.94000e-09 4.33e-07
2Phenylpropanoid biosynthesis49163 5.07000e-08 2.79e-06
3Phenylalanine metabolism38126 1.53000e-06 4.20e-05
4Plant-pathogen interaction45159 1.21000e-06 4.20e-05
5Flavonoid biosynthesis1122 5.86000e-05 1.29e-03
6Linoleic acid metabolism1124 1.58824e-04 2.50e-03
richFactor Pathway ID
10.2755906ko04075
20.3006135ko00940
30.3015873ko00360
40.2830189ko04626
50.5000000ko00941
60.4583333ko00591# 基础富集气泡图
ggplot(data,aes(x=richFactor,y=Pathway,size=R0vsR3,color=-log10(Qvalue))) + geom_point()
文章图片
image.png
# 更改颜色,主题,坐标轴标题
ggplot(data,aes(x=richFactor,y=Pathway,size=R0vsR3,color=-log10(Qvalue))) +
geom_point() + theme_bw() +
scale_colour_gradient(low="green",high="red") +
labs(x="GeneRatio",y="Pathway",title="Top20 enriched pathways",
colour=expression(-log[10]("QValue")),size="Gene number") +
theme(plot.title = element_text(hjust = 0.5))
文章图片
image.png ggpubr包绘制富集气泡图
library(ggpubr)
data$`-log10(Qvalue)` <- -log10(data$Qvalue)# 基础富集气泡图
ggscatter(data,x="richFactor",y="Pathway",
size = "R0vsR3",color = "-log10(Qvalue)")
文章图片
image.png
# 更改颜色,主题,坐标轴标题
ggscatter(data,x="richFactor",y="Pathway",
size = "R0vsR3",color = "-log10(Qvalue)",
xlab="GeneRatio",ylab="Pathway",
title="Top20 enriched pathways") +
theme_minimal() +
scale_colour_gradient(low="green",high="red") +
labs(colour=expression(-log[10]("QValue")),size="Gene number") +
theme(plot.title = element_text(hjust = 0.5),legend.position = "right")
文章图片
image.png
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: defaultlocale:
[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.936attached base packages:
[1] statsgraphicsgrDevices utilsdatasetsmethodsbaseother attached packages:
[1] ggpubr_0.2.1magrittr_1.5ggplot2_3.2.0loaded via a namespace (and not attached):
[1] Rcpp_1.0.5rstudioapi_0.10knitr_1.23tidyselect_0.2.5
[5] munsell_0.5.0colorspace_1.4-1 R6_2.4.0rlang_0.4.7
[9] dplyr_0.8.3tools_3.6.0grid_3.6.0gtable_0.3.0
[13] xfun_0.8withr_2.1.2htmltools_0.3.6yaml_2.2.0
[17] lazyeval_0.2.2assertthat_0.2.1 digest_0.6.20tibble_2.1.3
[21] ggsignif_0.5.0crayon_1.3.4purrr_0.3.2evaluate_0.14
[25] glue_1.3.1rmarkdown_1.13labeling_0.3compiler_3.6.0
[29] pillar_1.4.2scales_1.0.0pkgconfig_2.0.2
推荐阅读
- 一百二十三夜,请嫁给我
- 【生信技能树】R语言练习题|【生信技能树】R语言练习题 - 中级
- 一起来学习C语言的字符串转换函数
- C语言字符函数中的isalnum()和iscntrl()你都知道吗
- C语言浮点函数中的modf和fmod详解
- C语言中的时间函数clock()和time()你都了解吗
- 第四十三篇接纳孩子的感受
- 为什么孩子一定要学会可视化思维!
- C语言学习|第十一届蓝桥杯省赛 大学B组 C/C++ 第一场
- 如果鸽子会说话(二十三)