新闻媒体-太阳成tyc7111cc
发稿时间:2020-05-29来源:天昊生物
气泡图是r语音中的基础绘图,可用于展示三个变量之间的关系的图表,将一个变量放在x轴,另一个变量放在y轴,而第三个变量则用气泡的大小来表示。通常用于展示差异基因的表达情况、转录因子的分析、物种丰度数据的可视化、富集分析展示等。这里我们介绍2种绘制气泡图的方法:ggpubr绘制气泡图
和 ggplot 绘制气泡图 。
一ggpubr绘制气泡图
1. 加载ggpubr包
in [1]:
2. 数据读取由于表头是数字,需要添加参数check.names = fin [2]:
-
df = read.table('phylum_taxon_abundance.xls',header = t,row.names = 1,check.names = f)
-
head(df)
out[2]:
-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
-
proteobacteria 126573 92545 83038 75739 103697 116154 73868 76555 47648 61165 90984 86653 111958 95141 92972 102300
-
actinobacteria 12759 10186 50860 32437 34212 21024 64078 52398 46109 38587 46147 46310 46780 50249 32803 29345
-
bacteroidetes 18428 25557 16559 22848 7046 23059 4974 8066 4984 15941 14064 12966 10931 5047 14100 27364
-
acidobacteria 16566 26529 6636 16079 7563 10637 8352 11404 11755 7008 8292 9372 6405 5773 10853 6738
-
chloroflexi 6665 11038 12520 20040 22476 4146 23314 26628 32961 30103 14238 11799 9819 15672 7421 6116
-
firmicutes 6033 13830 21344 3293 18031 10253 12822 5480 35773 6208 13005 20341 7953 21295 19200 12794
3. 气泡图绘制3.1 绘制不带参数的气泡图in [3]:
out[3]:
3.2 添加和填充颜色in [4]:
-
ggballoonplot(df, color = "red", fill = "blue")
out[4]:
3.3 按照值的大小填充颜色,并制定气泡图形状in [5]:
-
ggballoonplot(df, fill = "value", shape =21 ,) gradient_fill(c("blue", "white", "red"))
out[5]:
3.4 填充数值show.label =f 默认不填充数值, show.label =t 填充数值选择size参数固定图形大小in [6]:
-
ggballoonplot(df, fill = "value", color = "lightgray",size = 3, show.label =f) gradient_fill(c("blue", "white", "red"))
out[6]:
二ggplot2绘制气泡图
1. 加载ggplot2包in [7]:
2. 数据预处理stack是堆栈的意思,默认按列堆数据in [8]:
-
data = stack(df)
-
colnames(data) = c('abundance','sample')
-
head(data)
out[8]:
-
abundance sample
-
126573 1
-
12759 1
-
18428 1
-
16566 1
-
6665 1
-
6033 1
in [9]:
-
data$phylum = rep(rownames(df), times = ncol(df))
-
head(data)
out[9]:
-
abundance sample phylum
-
126573 1 proteobacteria
-
12759 1 actinobacteria
-
18428 1 bacteroidetes
-
16566 1 acidobacteria
-
6665 1 chloroflexi
-
6033 1 firmicutes
添加分组信息,本次分析将16个样品分为2组,组名分别未a、bin [10]:
out[10]:
-
'1' '2' '3' '4' '5' '6' '7' '8' '9' '10' '11' '12' '13' '14' '15' '16'
in [11]:
out[11]:
in [12]:
out[12]:
-
'proteobacteria' 'actinobacteria' 'bacteroidetes' 'acidobacteria' 'chloroflexi' 'firmicutes' 'verrucomicrobia' 'planctomycetes' 'gemmatimonadetes' 'candidatus_saccharibacteria' 'thaumarchaeota' 'armatimonadetes' 'euryarchaeota' 'candidate_division_wps-1' 'cyanobacteria/chloroplast' 'chlamydiae' 'nitrospirae' 'ignavibacteriae' 'latescibacteria' 'candidate_division_wps-2' 'microgenomates' 'elusimicrobia' 'spirochaetes' 'aminicenantes' 'woesearchaeota'
in [13]:
out[13]:
in [14]:
-
group = rep(c('a','b'),each = 25*16/2)
-
length(group)
out[14]:
in [15]:
in [16]:
out[16]:
-
abundance sample phylum group
-
126573 1 proteobacteria a
-
12759 1 actinobacteria a
-
18428 1 bacteroidetes a
-
16566 1 acidobacteria a
-
6665 1 chloroflexi a
-
6033 1 firmicutes a
3. 气泡图绘制
in [16]:
-
ggplot(data, aes(x = sample, y = phylum, size = abundance, colour = group)) geom_point()
-
theme_bw() scale_size(range = c(0,6)) labs(x = "sample", y = "")
out[17]:
往期相关链接:
1、r基础篇
;;
;;
;
;;
;
2、r进阶
;
;
;
3、数据提交
;
;
;
;
4、表达谱分析
;;
5、医学数据分析
;;;;