如何在R中按染色体绘制热图 [英] How to plot a heat map by chromosome in R
本文介绍了如何在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:
我尝试使用ggplot和geom_rect(),但是没有运气.
I have tried using ggplot and geom_rect(), but with no luck.
任何帮助将不胜感激.
推荐答案
您可以尝试 plotly
包,这是一个开始:
You could try the plotly
package, here's a start:
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)))
这篇关于如何在R中按染色体绘制热图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文