R语言gggenes包,基因组箭头图




library(ggplot2)
library(gggenes)
data(example_genes)
head(example_genes)
head(example_subgenes)
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")
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()
# Mon May 24 08:21:57 2021 --对齐
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()
# Mon May 24 08:24:59 2021 ----箭头形状--------------------------
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()
# Mon May 24 08:25:21 2021 ----箭头方向--------------------------
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()
# Mon May 24 08:25:52 2021 --
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()
# Mon May 24 08:26:30 2021 ----标记亚基因位置--------------------------
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()
# Mon May 24 08:26:51 2021 --
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
)
# Mon May 24 08:28:18 2021 -- end
# Mon May 24 08:29:17 2021 -
# 字符编码:UTF-8
# R 版本:R x64 4.1 for window 10
# cgh163email@163.com
# 个人笔记不负责任,拎了个梨🍐🍈
.rs.restartR()
require(ggplot2)
require(gggenes)
rm(list = ls());gc()
#随机数模拟坐标散点:
mydt1 <- data.frame(
start = runif(100, 30, 35),
end = runif(100, 30, 35) ,
gene = sample(LETTERS[10:15], 100, replace =TRUE) ,
molecule = sample(LETTERS[1:5], 100, replace =TRUE),
strand = sample(LETTERS[16:21], 100, replace =TRUE),
co = substr(rainbow(100), 1, 7))
head(mydt1)# lat lon size type co
# Sun Jan 31 19:55:55 2021 --随机数模拟完毕
ggplot(mydt1,
aes(xmin=start,
xmax=end,
y=molecule,
fill=gene))+
geom_gene_arrow() # 基础
# Mon May 24 08:36:03 2021 --
ggplot(mydt1,
aes(xmin=start,
xmax=end,
y=molecule,
fill=gene))+
geom_gene_arrow()+
scale_fill_brewer(palette = 'Set3')+ # 填色
facet_wrap(scales = 'free',ncol = 1,~molecule) # 分组
# Mon May 24 08:40:19 2021 -----ex2-------------------------
dt <- mydt1[1:3,]
dt$molecule <- 'a'
dt$start <- c(1,3,5)
dt$end <- c(2,5,7)
ggplot(dt)+
geom_gene_arrow(aes(xmin=start,
xmax=end,
y=molecule,
fill=gene))
# Mon May 24 08:45:02 2021 ----小段--------------------------
dt2 <- data.frame(
molecule=rep('G4',5),
gene=rep('gA',5),
start=rep(0,5),
end=rep(15,5),
strand=rep('re',5),
subgene=letters[1:5],
from=c(2,5,7,7,9),
to=c(4,6,9,9,12),
or=rep(1,5),
fx =rep(1,5)
)
dt2
ggplot(dt2,
aes(xmin = start, xmax = end, y = strand)) +
geom_gene_arrow() + # 总段
geom_subgene_arrow(
data =dt2,
aes(
xsubmin = from,
xsubmax = to,
fill = subgene
)
)
# Mon May 24 10:46:27 2021 --text
ggplot(dt2,
aes(xmin = start, xmax = end, y = strand)) +
geom_gene_arrow() + # 总段
geom_subgene_arrow(
data =dt2,
aes(
xsubmin = from,
xsubmax = to,
fill = subgene
)
)+
geom_subgene_label(
data = dt2,
aes(xsubmin = from, xsubmax = to, label = subgene),
min.size = 0
)
# Mon May 24 08:21:57 2021 --对齐
data(example_genes)
dummies <- make_alignment_dummies(
example_genes,
aes(xmin = start, xmax = end, y = molecule, id = gene),
on = "genE"
)
# Mon May 24 08:24:59 2021 ----箭头形状--------------------------
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(10, "mm")) + # 箭头长度
# geom_gene_label(align = "left") +
# geom_blank(data = dummies) +
facet_wrap(~ molecule, scales = "free", ncol = 1) +
theme_genes()
# Mon May 24 10:55:58 2021 ----ex3--------------------------
ggplot(dt2,
aes(xmin = 1, xmax = 14, y = strand)) +
geom_gene_arrow(arrowhead_height = unit(3, "mm"), # 箭头高度
arrowhead_width = unit(10, "mm"), # 箭头长度
# ,fill='#FFFFCC',
color='#990033',
aes( forward = -1))+# 总段
geom_gene_arrow(arrowhead_height = unit(3, "mm"), # 箭头高度
arrowhead_width = unit(10, "mm"), # 箭头长度
# fill='#FFFFCC',
color='#990033',
aes( forward = 1,
xmin=2,xmax=15
))+# 总段
geom_subgene_arrow(
data =dt2,
aes(
xsubmin = from,
xsubmax = to,
fill = subgene
))+
geom_subgene_label(
data = dt2,
aes(xsubmin = from, xsubmax = to, label = subgene),
min.size = 0
)+
theme_genes()+ # 主题
ggtitle(label = 'gg双箭头线段图')
ggsave(filename = '双箭头线段图1.jpg',dpi=300)
网友评论