导读
gggenes: Draw Gene Arrow Maps in 'ggplot2'。
Github:gggens
CRAN:gggenes: Draw Gene Arrow Maps in 'ggplot2'
Author:Introduction to ‘gggenes’
注意:
R version >= 3.6
gggenes依赖的ggfittext需要R 3.6以上,导致我用R 3.4.1安装gggenes失败。后来改用R 3.6.1成功安装。
Linux conda安装R 3.6:
# conda config --show # 查看所有channel
conda install -c r r=3.6
一、输入数据
1. 基因组-基因-方向
library(ggplot2)
library(gggenes)
data(example_genes)
head(example_genes)
2. 基因组-基因-亚基因
head(example_subgenes)
二、画基因箭头图
1. 基础绘图
ggplot(example_genes, aes(xmin = start, xmax = end, y = molecule, fill = gene)) +
geom_gene_arrow() +
facet_wrap(~ molecule, scales = "free", ncol = 1) +
scale_fill_brewer(palette = "Set3")
2. 去掉背景
- theme_genes()
ggplot(example_genes, aes(xmin = start, xmax = end, y = molecule, fill = gene)) +
geom_gene_arrow() +
facet_wrap(~ molecule, scales = "free", ncol = 1) +
scale_fill_brewer(palette = "Set3") +
theme_genes()
3. 按geneE对齐
- make_alignment_dummies()
dummies <- make_alignment_dummies(
example_genes,
aes(xmin = start, xmax = end, y = molecule, id = gene),
on = "genE"
)
ggplot(example_genes, aes(xmin = start, xmax = end, y = molecule, fill = gene)) +
geom_gene_arrow() +
geom_blank(data = dummies) +
facet_wrap(~ molecule, scales = "free", ncol = 1) +
scale_fill_brewer(palette = "Set3") +
theme_genes()
4. 设置箭头形状
- geom_gene_label()
ggplot(example_genes, aes(xmin = start, xmax = end, y =
molecule, fill = gene, label = gene)) +
geom_gene_arrow(arrowhead_height = unit(3, "mm"), arrowhead_width = unit(1, "mm")) +
geom_gene_label(align = "left") +
geom_blank(data = dummies) +
facet_wrap(~ molecule, scales = "free", ncol = 1) +
scale_fill_brewer(palette = "Set3") +
theme_genes()
5. 控制箭头方向
example_genes$direction <- ifelse(example_genes$strand == "forward", 1, -1)
ggplot(
subset(example_genes, molecule == "Genome1"),
aes(xmin = start, xmax = end, y = strand, fill = gene, forward = direction)
) +
geom_gene_arrow() +
theme_genes()
ggplot(example_genes, aes(xmin = start, xmax = end, y = molecule, fill = gene, forward = direction)) +
geom_gene_arrow() +
facet_wrap(~ molecule, scales = "free", ncol = 1) +
scale_fill_brewer(palette = "Set3") +
theme_genes()
6. 标记亚基因位置
- geom_subgene_arrow()
ggplot(example_genes, aes(xmin = start, xmax = end, y = molecule)) +
facet_wrap(~ molecule, scales = "free", ncol = 1) +
geom_gene_arrow(fill = "white") +
geom_subgene_arrow(data = example_subgenes,
aes(xmin = start, xmax = end, y = molecule, fill = gene,
xsubmin = from, xsubmax = to), color="black", alpha=.7) +
theme_genes()
7. 标记某基因组中某基因的亚基因位置
- geom_subgene_label()
ggplot(subset(example_genes, molecule == "Genome4" & gene == "genA"),
aes(xmin = start, xmax = end, y = strand)
) +
geom_gene_arrow() +
geom_gene_label(aes(label = gene)) +
geom_subgene_arrow(
data = subset(example_subgenes, molecule == "Genome4" & gene == "genA"),
aes(xsubmin = from, xsubmax = to, fill = subgene)
) +
geom_subgene_label(
data = subset(example_subgenes, molecule == "Genome4" & gene == "genA"),
aes(xsubmin = from, xsubmax = to, label = subgene),
min.size = 0
)