[英]how to graph coordinates below a plot - ggplot2?
我正在嘗試制作一個像這里顯示的那樣的單一基因覆蓋圖。
我已經繪制了覆蓋率,但我仍然需要在相應的坐標中插入外顯子和內含子。 謝謝! 我的代碼:
ggplot(z, aes(x=inicio, y=promedio, fill=Technology, group=Technology, color=Technology))+
stat_smooth(
geom = 'area', method = 'loess', span = 1/3,
alpha = 1/2) +
scale_x_continuous(limits=c(30689060,30748122))+
theme_set(theme_bw())+
theme(legend.text = element_text (size = 12))+
xlab("Coordinates")+
ylab("Depth")+
ggtitle("TEX15")
如果沒有包含一些輸入數據和預期輸出的最小可重現示例(MRE),很難知道如何為您提供幫助。 例如,這是一個帶有一些“假”數據的 MRE:
library(tidyverse)
df <- data.frame(Coverage = runif(1000, 0, 7900))
p1 <- df %>%
ggplot(aes(x = Coverage)) +
geom_density(outline.type = "full", fill = "#D6B7C9") +
theme_minimal(base_size = 14) +
theme(axis.title.x = element_blank())
features1 <- tribble(~"feature", ~"start", ~"end",
"E1", 1, 1950,
"E5", 2986, 3237,
"L1", 4775, 6292)
features2 <- tribble(~"feature", ~"start", ~"end",
"E2", 1892, 2989,
"L2", 3373, 4794,
"E6", 7125, 7601,
"E7", 7604, 7900)
p2 <- features1 %>%
ggplot() +
geom_rect(aes(xmin = start, xmax = end,
ymin = 0, ymax = 1,
fill = feature),
color = "black") +
geom_text(aes(x = (start + end) / 2, y = 0.5, label = feature)) +
theme_void() +
theme(legend.position = "none")
p3 <- features2 %>%
ggplot() +
geom_rect(aes(xmin = start, xmax = end,
ymin = 0, ymax = 1,
fill = feature),
color = "black") +
geom_text(aes(x = (start + end) / 2, y = 0.5, label = feature)) +
theme_void() +
theme(legend.position = "none")
library(patchwork)
p1 / p2 / p3 + plot_layout(nrow = 3, heights = c(1, 0.1, 0.1))
由reprex 包於 2022-06-16 創建 (v2.0.1)
這種方法是否適合您的單基因覆蓋圖? 如果不是,你想改變什么?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.