简体   繁体   English

如何在R中用染色体绘制热图

[英]How to plot a heat map by chromosome in R

I have a data table in the following format: 我有一个以下格式的数据表:

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))
)

And I am trying to plot a figure similar (but not identical) to this: 我试图绘制一个类似(但不完全相同)的数字:

在此输入图像描述

I have tried using ggplot and geom_rect(), but with no luck. 我尝试过使用ggplot和geom_rect(),但没有运气。

Any help will be greatly appreciated. 任何帮助将不胜感激。

You could try the plotly package, here's a start: 你可以尝试一下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)))

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM