【问题标题】:Heat maps with bar plots or mosaic plots in rr中带有条形图或马赛克图的热图
【发布时间】:2012-08-19 21:26:37
【问题描述】:

我有一个矩阵,显示了 2 个不同地点的物种之间的性状相似性,即

relationship<-matrix(1:6,ncol=2)
colnames(relationship)<-c("Sp1","Sp2")
rownames(relationship)<-c("Sp3","Sp4","Sp5")

     Sp1 Sp2
Sp3   1   4
Sp4   2   5
Sp5   3   6

我还有一个矩阵显示它们在每个站点的丰度

abundance<-matrix(1:5,ncol=1)
rownames(abundance)<-c("Sp1","Sp2","Sp3","Sp4","Sp5")
colnames(abundance)<-"abundance"

       abundance
 Sp1         1
 Sp2         2
 Sp3         3
 Sp4         4
 Sp5         5

我想创建一个带有条形图的热图,如下所示:

对原始问题的更新

或者(如 BenBarnes 所建议)我想创建一个马赛克图,使用丰度来控制瓷砖的大小和矩阵来指示颜色的“强度”。因此,对于上面的马赛克图示例,非常粗略地看起来像这样:

另外我想知道您对哪种方法最清楚地显示物种之间的关系以及它们的丰度之间的关系有什么看法?

【问题讨论】:

  • 您会考虑使用马赛克图吗?来自graphicsvcd 包?
  • 当然!只要达到最终目标,我就可以非常灵活地完成它。感谢您的观看。
  • 那么这会涉及到创建 2 个列联表来表示丰度,然后使用关系矩阵来指定“平铺”颜色吗?

标签: image r matrix histogram


【解决方案1】:

使用graphics 包函数(条形图、图像等),您可以执行以下操作。

bp1 <- barplot(t(abundance[3:5, ]), width = 0.2, space = 0.7, plot = FALSE)
bp2 <- barplot(t(abundance[1:2, ]), horiz = TRUE, width = 0.05, space = 1, plot = FALSE)


par(fig = c(0, 0.8, 0, 0.8), new = TRUE)
par(xaxt = "n", yaxt = "n")
image(relationship)
par(fig = c(0, 0.8, 0.55, 1), new = TRUE)
barplot(t(abundance[3:5, ]), width = 0.2, space = 0.7)
text(bp1, abundance[3:5,] - 0.5, c("Sp3", "Sp4", "Sp5"))
par(fig = c(0.65, 1, 0, 0.8), new = TRUE)   
barplot(t(abundance[1:2, ]), horiz = TRUE, width = 0.05, space = 1)
text(abundance[1:2,] - 0.5, bp2, c("Sp1", "Sp2"))

【讨论】:

  • 感谢您的回答。这非常有用。您能否解释一下代码的不同步骤中发生的情况。
猜你喜欢
  • 2021-01-09
  • 1970-01-01
  • 2020-07-07
  • 1970-01-01
  • 1970-01-01
  • 2012-08-28
  • 2017-09-23
  • 2016-04-14
相关资源
最近更新 更多