首页 > 解决方案 > 具有特定输入格式的染色体上的热图

问题描述

我尝试使用热图绘制每个支架和每个物种的值。我已经查阅了以下帖子来设置我的脚本: 如何在 R 中按染色体绘制热图

但是输入表本身就很不寻常,遵循这样的格式:

structure(list(scaffolds = c("Scaffolds_0", "Scaffolds_1", "Scaffolds_2", 
"Scaffolds_3", "Scaffolds_4", "Scaffolds_5", "Scaffolds_6", "Scaffolds_7", 
"Scaffolds_8"), Specie_1 = c(0L, 0L, 0L, 0L, 0L, 0L, 2L, 0L, 
0L), Specie_2 = c(0L, 0L, 2L, 0L, 0L, 0L, 2L, 0L, 0L), Specie_3 = c(0L, 
0L, 2L, 0L, 0L, 0L, 4L, 0L, 0L), Specie_4 = c(0L, 0L, 0L, 0L, 
0L, 2L, 2L, 0L, 0L), Specie_5 = c(0L, 0L, 2L, 0L, 0L, 0L, 2L, 
0L, 0L)), class = "data.frame", row.names = c(NA, -9L))

我希望每个物种输出一列,并使用不同颜色比较脚手架值,如下图所示:

热图输出

有谁知道plot_ly在 ggplot2 中是否可以产生这样的情节?

标签: rggplot2plotly

解决方案


我最终想出了如何绘制这个数据集。

我使用的包:

library(reshape2)
library(ggplot2)

该表已使用 melt() 函数从宽转换为长:

melt_table <- melt(table)

列必须重新命名:

colnames(melt_table) <- c("Scaffolds", "Species", "Values")

并绘制了热图ggplot2::geom_tile

ggplot(melt_table, aes(Species , Scaffolds)) +
  geom_tile(aes(fill = Values), colour = "white") +
  scale_fill_gradient(low = "white", high = "red")


推荐阅读