gganatogram绘制解剖图(1)之人体篇
2021-02-21 本文已影响0人
R语言数据分析指南
gganatogram软件包是一个可以快速绘制各种动植物解剖图的R包,今天来介绍如何通过其绘制人体解剖图。喜欢的小伙伴可以关注个人公众号R语言数据分析指南持续分享更多优质资源,在此先行拜谢了!!
由于我一直习惯安装开发版R包,各位可以根据个人喜好安装官方版也可,如何方便如何来,如果安装gituhub版R包有困难请给我留言,可以出一个完美的教程给各位
安装必须的R包
devtools::install_github("jespermaag/gganatogram")
devtools::install_github("mdsumner/ggpolypath")
devtools::install_github("jrowen/rhandsontable")
install.packages("ggpolypath")
install.packages("rhandsontable")
加载R包
library(gganatogram)
library(tidyverse)
library(viridis)
library(patchwork)
创建人体解剖图图像
hgMale <- gganatogram(data=hgMale_key,
fillOutline='#a6bddb', organism='human', sex='male', fill="colour") +
theme_void()
hgFemale <- gganatogram(data=hgFemale_key,
fillOutline='#a6bddb', organism='human', sex='female', fill="colour") +
theme_void()
hgMale+hgFemale
用数值进行填充
hgMale <- gganatogram(data=hgMale_key,
fillOutline='#440154FF', organism='human',
sex='male', fill="value") + theme_void() +
scale_fill_viridis()
hgFemale <- gganatogram(data=hgFemale_key,
fillOutline='#440154FF', organism='human',
sex='female', fill="value") + theme_void() +
scale_fill_viridis()
hgMale+hgFemale
创建包含器官,颜色和值的数据框进行绘图
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("red","red","purple","purple", "orange", "orange", "orange"),
value = c(10, 5, 1, 8, 2, 5, 5),
stringsAsFactors=F)
gganatogram(data=organPlot,fillOutline='#a6bddb',
organism='human', sex='male', fill="colour")+
theme_void()
hgMale_key绘制所有可用的组织
hgMale_key$organ
[1] "thyroid_gland" "bone_marrow" "frontal_cortex"
[4] "prefrontal_cortex" "pituitary_gland" "aorta"
[7] "gastroesophageal_junction" "left_ventricle" "caecum"
[10] "ileum" "rectum" "nose"
[13] "breast" "tongue" "left_atrium"
[16] "pulmonary_valve" "mitral_valve" "penis"
[19] "nasal_pharynx" "spinal_cord" "throat"
[22] "tricuspid_valve" "diaphragm" "liver"
[25] "stomach" "spleen" "duodenum"
[28] "gall_bladder" "pancreas" "colon"
[31] "small_intestine" "appendix" "smooth_muscle"
[34] "urinary_bladder" "bone" "cartilage"
[37] "esophagus" "salivary_gland" "parotid_gland"
[40] "submandibular_gland" "skin" "pleura"
[43] "brain" "heart" "adrenal_gland"
[46] "lymph_node" "adipose_tissue" "skeletal_muscle"
[49] "leukocyte" "temporal_lobe" "atrial_appendage"
[52] "coronary_artery" "hippocampus" "vas_deferens"
[55] "seminal_vesicle" "epididymis" "tonsil"
[58] "lung" "amygdala" "trachea"
[61] "bronchus" "nerve" "cerebellum"
[64] "cerebellar_hemisphere" "kidney" "renal_cortex"
[67] "testis"
gganatogram(data=hgMale_key,
fillOutline='#a6bddb', organism='human',
sex='male', fill="colour") +theme_void()
根据每个器官的值进行颜色填充
gganatogram(data=organPlot, fillOutline='#a6bddb',
organism='human', sex='male', fill="value") +
theme_void() +
scale_fill_gradient(low = "white", high = "red")
使用facet_wrap来对数据进行可视化。首先在类型列中创建两个具有不同值和条件的数据框
compareGroups <- rbind(data.frame(organ = c("heart",
"leukocyte", "nerve", "brain", "liver", "stomach", "colon"),
colour = c("red", "red", "purple", "purple",
"orange", "orange", "orange"),
value = c(10, 5, 1, 8, 2, 5, 5),
type = rep('Normal', 7),
stringsAsFactors=F),
data.frame(organ = c("heart", "leukocyte",
"nerve", "brain", "liver", "stomach", "colon"),
colour = c("red", "red", "purple", "purple",
"orange", "orange", "orange"),
value = c(5, 5, 10, 8, 2, 5, 5),
type = rep('Cancer', 7),
stringsAsFactors=F))
gganatogram(data=compareGroups,
fillOutline='#a6bddb', organism='human', sex='male', fill="value") +
theme_void() +
facet_wrap(~type) +
scale_fill_gradient(low = "white", high = "red")
根据组织类型进行分面
gganatogram(data=hgMale_key, outline = T,
fillOutline='#a6bddb', organism='human', sex='male', fill="colour") +
facet_wrap(~type, ncol=4) +
theme_void()
所有女性组织
> hgFemale_key$organ
[1] "atrial_appendage" "ectocervix" "hippocampus"
[4] "pleura" "bronchus" "trachea"
[7] "lung" "tonsil" "submandibular_gland"
[10] "breast" "spinal_cord" "pancreas"
[13] "liver" "colon" "bone_marrow"
[16] "urinary_bladder" "stomach" "duodenum"
[19] "esophagus" "gall_bladder" "spleen"
[22] "small_intestine" "placenta" "endometrium"
[25] "vagina" "aorta" "pituitary_gland"
[28] "gastroesophageal_junction" "caecum" "appendix"
[31] "ileum" "left_atrium" "left_ventricle"
[34] "pulmonary_valve" "mitral_valve" "diaphragm"
[37] "bone" "cartilage" "throat"
[40] "rectum" "nasal_septum" "nasal_pharynx"
[43] "cerebellum" "cerebellar_hemisphere" "prefrontal_cortex"
[46] "frontal_cortex" "nose" "temporal_lobe"
[49] "cerebral_cortex" "kidney" "renal_cortex"
[52] "coronary_artery" "tricuspid_valve" "thyroid_gland"
[55] "skin" "parotid_gland" "adipose_tissue"
[58] "heart" "smooth_muscle" "brain"
[61] "adrenal_gland" "lymph_node" "skeletal_muscle"
[64] "ovary" "leukocyte" "salivary_gland"
[67] "fallopian_tube" "uterus" "uterine_cervix"
[70] "nerve"
gganatogram(data=hgFemale_key, outline = T, fillOutline='#a6bddb',
organism='human', sex='female', fill="colour") +theme_void()
根据组织类型进行分面
gganatogram(data=hgFemale_key, outline = T,
fillOutline='#a6bddb', organism='human', sex='female', fill="colour") +
facet_wrap(~type, ncol=4) +
theme_void()
这一节就介绍如何绘制人体的解剖图,接着将介绍其它动植物及细胞结构的解剖图绘制,后面的内容更加精彩,喜欢的小伙伴可以关注我的公众号R语言数据分析指南在此先行拜谢了