绘制靠近系统发育分类群的方块

Plot squares close to phylogeny taxa

我正在尝试在系统发育的终端节点旁边绘制一些彩色方块。但是,我无法让方块靠近终端节点。我认为这与分类群标签有关——尽管它们已关闭。

我打算绘制一个接一个的正方形列,这就是为什么我不能将 tip.labels 与正方形字符一起使用的原因。

这是我的测试函数:

.squares = function(colour, start_point, n){
    colour = colour[length(colour):1]

    inc = 200
    ## Plot either points or rectangles. Dependant on arugment
    rect(start_point, 0.5:(n-0.5), start_point+inc, 
         1.5:(n+0.5), col = colour)
    start_point = start_point + inc ## inc is the width of each box. 
    start_point
}

这里是测试代码:

library(ape)

n = 20
tree = rcoal(n, tip.label = letters[1:n])
t = plot(tree, show.tip.label = FALSE, no.margin = TRUE)

abline(v = t$x.lim[2], col = "red", lwd = 5)
.squares(rep("red", 20), start_point = t$x.lim[2], n = n)

给出:

我不知道如何缩小方块和终端节点之间的差距。

如有任何指示,我们将不胜感激。由于我还将绘制多列正方形,因此了解如何在不进入边距的情况下添加更多列会很有帮助。

谢谢

我似乎也无法重现您的错误(在提示限制处正确添加了水平线)。

但是,您的问题似乎与 Liam Revell's excellent blog. Have a look at this code, that one or even better, this final one 上的帖子非常相似。

在你的情况下,你可以使用类似的东西:

## phytools package
library(phytools)

## The tree
n = 20
tree = rcoal(n, tip.label = letters[1:n])

## The data
data <- data.frame(rep(1, n), rep(2, n))
colnames(data) <- c("Something", "SomethingElse")

## The plot (using a near 0 font size plot)
object <- plotTree.datamatrix(tree, data, sep=0, srt=70, yexp=1.05, fsize=0.0001)