r - 具有特定输入格式的染色体上的热图
问题描述
我尝试使用热图绘制每个支架和每个物种的值。我已经查阅了以下帖子来设置我的脚本: 如何在 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 中是否可以产生这样的情节?
解决方案
我最终想出了如何绘制这个数据集。
我使用的包:
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")
推荐阅读
- flutter - 包装小部件以提供选择多个用户时常见的堆叠效果
- sed - 替代在循环内使用 sed
- c++ - 我可以在每次使用后清除 default_random_engine 生成器吗?
- c# - 有谁知道可以序列化私人成员的 ServiceStack.Text 分支?
- function - 如何模拟状态数据以传递给函数?
- python - Django Rest / Sum 相同硬币的响应值
- azure - 无法访问 Microsoft Graph 列表消息 API
- java - 正则表达式提取具有此模式的文本
- java - Java LocalDateTime 在不同的服务器上给出不同的输出。相同时区配置
- python - Pytest:测试具有不同全局变量的方法