其他
R可视化15|27种常见物种解剖图轻松绘制
"pythonic生物人"的第113篇分享
本文介绍ggplot2 扩展模块「gganatogram」绘制物种的解剖图,可绘制的「27种物种」如下图,该文会详细介绍「男性、女性、雌鼠、雄鼠及人体细胞」的结构图,其它物种的可按需摸索。
本文目录
gganatogram使用
完整人体和小鼠解剖图
按colour填充
按value填充
自定义人体解剖图
人体所有器官名称
指定器官解剖图
按器官type绘制分面图
重点部位解剖图
绘制人细胞结构图
绘制细胞全组织图
绘制细胞各个组织图
其它24种物种解剖图
gganatogram使用
> gganatogram #gganatogram使用
function (data = NULL, outline = TRUE, fillOutline = "lightgray",
organism = "human", #指定物种类别
sex = "male",
fill = "colour", #指定填充类型,colour还是value填充
anatogram = NULL, ggplot2_only = FALSE)
{。。。。。。。。。。。。。}
以下重点介绍人解剖图绘制。
完整人体和小鼠解剖图
按colour填充
library(gganatogram)
library(dplyr)
library(viridis)
library(gridExtra)
options(repr.plot.width = 4.5, repr.plot.height = 4, repr.plot.res = 300)
#男性
hgMale <- gganatogram(data=hgMale_key, fillOutline='grey', organism='human', sex='male', fill="colour") + theme_void()
#女性
hgFemale <- gganatogram(data=hgFemale_key, fillOutline='pink', organism='human', sex='female', fill="colour") + theme_void()
#雄鼠
mmMale <- gganatogram(data=mmMale_key, fillOutline='#a6bddb', organism='mouse', sex='male', fill="colour") + theme_void()
#雌鼠
mmFemale <- gganatogram(data=mmFemale_key, outline = T, fillOutline='#a6bddb', organism='mouse', sex='female', fill="colour") +theme_void()
grid.arrange(hgMale, hgFemale, mmMale, mmFemale, ncol=2)
按value填充
调色盘的使用可参考:R可视化07|ggplot2图层-标度图层(scale layer)-颜色盘篇
hgMale <- gganatogram(data=hgMale_key, fillOutline='#440154FF', organism='human', sex='male', fill="value") + theme_void() + scale_fill_viridis_c(option = "magma")
hgFemale <- gganatogram(data=hgFemale_key, fillOutline='#440154FF', organism='human', sex='female', fill="value") + theme_void() + scale_fill_distiller(palette = "YlOrBr")
mmMale <- gganatogram(data=mmMale_key, fillOutline='#440154FF', organism='mouse', sex='male', fill="value") + theme_void() + scale_fill_viridis()
mmFemale <- gganatogram(data=mmFemale_key, outline = T, fillOutline='#440154FF', organism='mouse', sex='female', fill="value") +theme_void() + scale_fill_distiller(palette = "RdPu")
grid.arrange(hgMale, hgFemale, mmMale, mmFemale, ncol=2)
自定义人体解剖图
有时候只想绘制某些关键结构的解剖图,可以自定义想要展示的部位。
人体所有器官名称
以男性为例,如下,有100多种器官,每个器官有「type,colour,value」三个指标:
> hgMale_key
organ type colour value
1 thyroid_gland other #41ab5d 4.6726366
2 bone_marrow other #41ab5d 3.3100146
3 frontal_cortex nervous_system purple 15.5068903
4 prefrontal_cortex nervous_system purple 1.8132048
5 pituitary_gland other #41ab5d 12.8793088
6 aorta circulation red 17.3028520
7 gastroesophageal_junction digestion orange 10.2065743
8 left_ventricle circulation red 2.4710974
9 caecum digestion orange 6.3062239
10 ileum digestion orange 3.0944341
11 rectum digestion orange 18.1526010
12 nose other #41ab5d 10.0435948
13 breast other #41ab5d 13.2018267
14 tongue digestion orange 19.0006837
15 left_atrium circulation red 9.3540431
16 pulmonary_valve circulation red 19.0279608
17 mitral_valve circulation red 8.4877200
18 penis reproductive #d95f02 10.5165066
19 nasal_pharynx other #41ab5d 4.8937552
20 spinal_cord nervous_system purple 15.7984266
21 throat digestion orange 4.0821599
22 tricuspid_valve other #41ab5d 9.7141877
23 diaphragm respiratory steelblue 2.9218888
24 liver digestion orange 9.4941773
25 stomach digestion orange 16.0912459
26 spleen digestion orange 8.5655954
27 duodenum digestion orange 17.9352352
28 gall_bladder digestion orange 17.3524552
29 pancreas digestion orange 7.5327137
30 colon digestion orange 7.5698419
31 small_intestine digestion orange 11.6291609
32 appendix other #41ab5d 12.4296024
33 smooth_muscle other #41ab5d 11.2084438
34 urinary_bladder digestion orange 5.5169661
35 bone other #41ab5d 5.2434188
36 cartilage other #41ab5d 13.7053463
37 esophagus digestion orange 7.1556004
38 salivary_gland other #41ab5d 18.5350091
39 parotid_gland other #41ab5d 4.0061764
40 submandibular_gland other #41ab5d 13.6965831
41 skin other #41ab5d 7.7031574
42 pleura other #41ab5d 16.5005984
43 brain nervous_system purple 19.7473604
44 heart circulation red 12.4137398
45 adrenal_gland other #41ab5d 6.9400360
46 lymph_node circulation red 15.7463740
47 adipose_tissue other #41ab5d 11.6300832
48 skeletal_muscle other #41ab5d 6.0012383
49 leukocyte circulation red 18.6572430
50 temporal_lobe nervous_system purple 2.7726517
51 atrial_appendage other #41ab5d 8.4522134
52 coronary_artery circulation red 5.1979311
53 hippocampus nervous_system purple 2.2728449
54 vas_deferens nervous_system purple 16.7526544
55 seminal_vesicle reproductive #d95f02 2.7194218
56 epididymis reproductive #d95f02 14.4341658
57 tonsil digestion orange 8.7993906
58 lung respiratory steelblue 13.8730005
59 amygdala nervous_system purple 5.5438625
60 trachea digestion orange 2.3591876
61 bronchus respiratory steelblue 15.1446414
62 nerve nervous_system purple 4.3844786
63 cerebellum nervous_system purple 4.5441280
64 cerebellar_hemisphere nervous_system purple 0.3210069
65 kidney digestion orange 9.1834168
66 renal_cortex digestion orange 19.0341405
67 testis reproductive #d95f02 8.3871708
68 prostate reproductive #d95f02 14.1272101
指定器官解剖图
自定义一个 data.frame指定需要展示的器官名称,type,value及colour。
options(repr.plot.width =5.5, repr.plot.height = 3, repr.plot.res = 300)
organPlot <- data.frame(organ = c("heart", "leukocyte", "nerve", "brain", "liver", "stomach", "colon"), #指定绘制的器官
type = c("circulation", "circulation", "nervous system", "nervous system", "digestion", "digestion", "digestion"),#器官类型
colour = c('#dc2624', '#2b4750','#45a0a2', '#e87a59', '#7dcaa9','#649E7D','#dc8018'), #器官的颜色
value = c(10, 5, 1, 8, 2, 5, 5), #器官填充值
stringsAsFactors=F)
p1 <- gganatogram(data=organPlot, fillOutline="#c72e29", #人体填充色
organism='human', sex='male', fill="colour") + theme_void()
p2 <- gganatogram(data=organPlot, fillOutline="#c72e29",
organism='human', sex='male', fill="value") + theme_void() + scale_fill_distiller(palette = "RdPu")
grid.arrange(p1,p2, ncol=2)
按器官type绘制分面图
options(repr.plot.width =5.5, repr.plot.height = 6, repr.plot.res = 500)
#女性
p1 <- gganatogram(data=hgMale_key, outline = T, fillOutline='#a6bddb', organism='human', sex='male', fill="colour") +
facet_wrap(~type, ncol=4) +
theme_void()
#男性
p2 <- gganatogram(data=hgFemale_key, outline = T, fillOutline='#a6bddb', organism='human', sex='female', fill="colour") +
facet_wrap(~type, ncol=4) +
theme_void()
grid.arrange(p1,p2)
重点部位解剖图
options(repr.plot.width =2.5, repr.plot.height =2, repr.plot.res = 300)
hgFemale_key %>%
dplyr::filter(type=='reproductive') %>%
gganatogram( outline = T, fillOutline='#a6bddb', organism='human', sex='female', fill="colour") +
theme_void() +
coord_cartesian(xlim = c(30, 75), ylim = c(-110, -80))
hgMale_key %>%
dplyr::filter(type=='reproductive') %>%
gganatogram( outline = T, fillOutline='#a6bddb', organism='human', sex='male', fill="colour") +
theme_void() +
coord_cartesian(xlim = c(30, 75), ylim = c(-110, -80))
绘制人细胞结构图
这里的细胞结构来自2017年_Science_上的一篇细胞图谱Subcellular locations in the Cell Atlas的文章,感兴趣的小伙伴可以去好好读一下。
绘制细胞全组织图
options(repr.plot.width =4.5, repr.plot.height =4, repr.plot.res = 300)
p1 <- gganatogram(data=cell_key[['cell']], outline = T, fillOutline='steelblue', organism="cell", fill="colour") +theme_void() + coord_fixed()
p2 <- gganatogram(data=cell_key[['cell']], outline = T, fillOutline='lightgray', organism="cell", fill="value") +theme_void() + coord_fixed() + scale_fill_distiller(palette = "RdPu")
grid.arrange(p1,p2)
绘制细胞各个组织图
options(repr.plot.width =4.5, repr.plot.height =6, repr.plot.res = 300)
figureList <- list()
for (i in 1:nrow(cell_key[['cell']])) {
figureList[[i]] <- gganatogram(data=cell_key[['cell']][i,], outline = T, fillOutline='steelblue', organism="cell", fill="colour") +theme_void() +ggtitle(cell_key[['cell']][i,]$organ) + theme(plot.title = element_text(hjust=0.5, size=8)) + coord_fixed()
}
do.call(grid.arrange, c(figureList[1:24], ncol=4))
其它24种物种解剖图
物种名称如下。
> names(other_key)#其它物种名称
[1] "anolis_carolinensis"
[2] "arabidopsis_thaliana"
[3] "bos_taurus"
[4] "brachypodium_distachyon.flower_parts"
[5] "brachypodium_distachyon.whole_plant"
[6] "gallus_gallus"
[7] "hordeum_vulgare.flower_parts"
[8] "hordeum_vulgare.whole_plant"
[9] "macaca_mulatta"
[10] "monodelphis_domestica"
[11] "oryza_sativa.flower_parts"
[12] "oryza_sativa.whole_plant"
[13] "papio_anubis"
[14] "rattus_norvegicus"
[15] "solanum_lycopersicum.flower_parts"
[16] "solanum_lycopersicum.whole_plant"
[17] "sorghum_bicolor.flower_parts"
[18] "sorghum_bicolor.whole_plant"
[19] "tetraodon_nigroviridis"
[20] "triticum_aestivum.flower_parts"
[21] "triticum_aestivum.whole_plant"
[22] "xenopus_tropicalis"
[23] "zea_mays.flower_parts"
[24] "zea_mays.whole_plant"
所有物种展示如下。
options(repr.plot.width = 4.5, repr.plot.height = 15, repr.plot.res = 300)
plotList <- list()
for (organism in names(other_key)) {
plotList[[organism]] <- gganatogram(data=other_key[[organism]], outline = T, fillOutline='white', organism=organism, sex='female', fill="colour") +
theme_void() +
ggtitle(organism) +
theme(plot.title = element_text(hjust=0.5, size=9)) +
coord_fixed()
}
do.call(grid.arrange, c(plotList[1:24], ncol=2))
本文结束,更多好文,欢迎关注公众号:「pythonic生物人」
有意见请移步到QQ群629562529反馈,一起进步哈!