【问题标题】:How to plot a heat map by chromosome in R如何在R中按染色体绘制热图
【发布时间】:2019-04-28 18:01:15
【问题描述】:

我有一个格式如下的数据表:

set.seed(1)

dt <- data.table(
chromosome = c(rep(1, 100), 
     rep(2, 100), 
     rep(3, 80)),
mb_from = c(seq(1, 1000, by=10),
      seq(1, 1000, by=10),
      seq(1, 800, by=10)),
mb_to = c(seq(10, 1000, by=10),
    seq(10, 1000, by=10),
    seq(10, 800, by=10)),
score = c(sample(1:10, 100, replace = T),
       sample(1:10, 100, replace = T),
       sample(1:10, 80, replace = T))
)

我正在尝试绘制一个与此类似(但不相同)的图形:

我尝试过使用 ggplot 和 geom_rect(),但没有成功。

任何帮助将不胜感激。

【问题讨论】:

  • 你能分享一下你尝试过的东西以及它与你想要的有什么不同吗?
  • 可能类似于:ggplot(dt) + geom_rect(aes(xmin = chromosome - 0.3, xmax = chromosome + 0.3, ymin = mb_from, ymax = mb_to, fill = score)) + scale_y_reverse() + scale_fill_distiller(palette = "RdYlBu")

标签: r ggplot2 heatmap


【解决方案1】:

你可以试试plotly 包,这是一个开始:

library(dplyr)
library(plotly)
library(RColorBrewer)

dat <- apply(dt,
      1,
      function(x) data.table(chromosome = x["chromosome"], mb = x["mb_from"]:x["mb_to"], score = x["score"])
) %>%
  rbindlist()

plot_ly(dat, x = ~chromosome, y = ~mb, z = ~score, type = "heatmap",
        colors = "RdYlBu", reversescale = T) %>%
  layout(yaxis = list(range = c(1000, 0)))

【讨论】:

    猜你喜欢
    • 2013-07-19
    • 1970-01-01
    • 2016-02-17
    • 1970-01-01
    • 2019-08-09
    • 2020-04-14
    • 1970-01-01
    • 1970-01-01
    • 2015-03-31
    相关资源
    最近更新 更多