我的資料(多序列比對)如下所示:
rand.mat <- matrix(sample(c("A", "T", "C", "G"), size = 250 * 50, replace = T),
ncol = 250, nrow = 50)
rownames(rand.mat) <- paste0("gene_", 1:nrow(rand.mat))
rand.df <- rand.mat %>% reshape2::melt()
dir.create("~/test/wrap_plot/", showWarnings = F, recursive = T)
p <- rand.df %>% ggplot(aes(x = Var2, y = Var1, label = value, color = value))
geom_text(size = 2)
theme_bw()
scale_x_continuous(expand = expansion(add = 1))
ggsave("~/test/wrap_plot/before_wrap.png", width = 25, height = 8)

它比它的高寬得多。這個長寬比需要保持,因為讀者需要能夠看到每個字母(我不能擠壓情節使其變窄)
但是,為了在信紙上展示這一點,我想在下一行顯示圖的后半部分(“包裝”圖):

我想知道是否有辦法自動將情節包裝在 ggplot2 中?謝謝!!
uj5u.com熱心網友回復:
rand.df %>%
mutate(half = Var2 %/% median(Var2)) %>%
ggplot(aes(x = Var2, y = Var1, label = value, color = value))
geom_text(size = 2)
scale_x_continuous(expand = expansion(add = 1))
facet_wrap(~half, scales = "free_x", ncol = 1)
theme_bw()
theme(strip.text = element_blank())

轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/493099.html
