**条件:ggplot2 ,ggpolypath
1、首先安装对应的包:
devtools::install_github("jespermaag/gganatogram")
install.packages('shiny')
install.packages('dplyr')
install.packages("viridis")
install.packages("gridExtra")
library(gganatogram)
library(dplyr)
library(viridis)
library(gridExtra)
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()
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=4)
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()
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_viridis()
grid.arrange(hgMale, hgFemale, mmMale, mmFemale, ncol=2)
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)
head(organPlot)
gganatogram(data=organPlot, fillOutline='#a6bddb', organism='human', sex='male', fill="colour")
会得到以下图
去掉标尺与背景:
gganatogram(data=organPlot, fillOutline='#a6bddb', organism='human', sex='male', fill="colour") + theme_void()
查看还可以进行注释的器官:
hgMale_key$organ
画出男性:
gganatogram(data=hgMale_key, fillOutline='#a6bddb', organism='human', sex='male', fill="colour") +theme_void()
去掉外周,只留下神经系统:
organPlot %>%
dplyr::filter(type %in% c('circulation', 'nervous system')) %>%
gganatogram(outline=F, 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")
画出部分器官:如心脏,肝脏,胃等。
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()
2、查看女性器官列表:
hgFemale_key$organ
查看空白的女性器官图:
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()
女性生殖系统的实现:
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))
3、小鼠器官的实现:
gganatogram(data=mmMale_key, outline = T, fillOutline='#a6bddb', organism='mouse', sex='male', fill="colour") +theme_void() +coord_fixed()
小鼠主要器官的实现:
gganatogram(data=mmMale_key, outline = T, fillOutline='#a6bddb', organism='mouse', sex='male', fill="colour") +theme_void()+facet_wrap(~type, ncol=4)
mmFemale_key$organ
雌鼠主要器官的实现:
gganatogram(data=mmFemale_key, outline = T, fillOutline='#a6bddb', organism='mouse', sex='female', fill="colour") +theme_void() +coord_fixed()
4、细胞的实现:
length(cell_key)
#> [1] 1
cell_key##查看细胞的大小与类型等
gganatogram(data=cell_key[['cell']], outline = T, fillOutline='steelblue', organism="cell", fill="colour") +theme_void() + coord_fixed()
5、别的动物与器官:
length(other_key)
#> [1] 24
names(other_key)
library(gridExtra)
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:4], ncol=2))