返回R上函数[pvclust]的树形图。

huangapple go评论72阅读模式
英文:

Return horizontally a dendrogram of the function [pvclust] on R

问题

我想返回一个类似上面的dendrogram的结果,同时保留信息(高度、au值、bp值和边值)。

要获得包含第一个树状图信息的这个树状图

我尝试了以下公式,但没有成功:

  • plot_horiz.dendrogram(pv, side = F)
  • plot(pv, ylim=c(0,0.004), horiz = F)
  • pv <- as.dendrogram(pv)
    plot(pv, horiz = T)

谢谢。

英文:

I would like to return a dendrogram of the [pvclust] function as above without losing the information (height, au value, bp value and edge value).

This dendrogram

To obtain this dendrogram with the information from the first dendrogram

I tried the following formulas but it didn't work:

  • plot_horiz.dendrogram(pv, side = F)
  • plot(pv, ylim=c(0,0.004), horiz = F)
  • pv <-as.dendrogram(pv)
    plot(pv, horiz = T)

Thanks

答案1

得分: 0

你需要修改pvclust的文本函数,就像这里的mytext是定制版本一样(你可以复制粘贴它)

mytext = function (x, col = c(au = 2, bp = 3, edge = 8), print.num = TRUE, 
          float = 0.01, cex = NULL, font = NULL, ...) 
{
  if (length(col) == 3 && is.null(names(col))) 
    names(col) <- c("au", "bp", "edge")
  axes <- pvclust:::hc2axes(x$hclust)
  usr <- par()$usr
  wid <- usr[4] - usr[3]
  num_str <- lapply(x$edges[seq_len(which(names(x$edges) == 
                                            "bp")], function(p) round(p * 100))
  for (i in names(num_str)) {
    num_str[[i]][length(num_str[[i]])] <- i
  }
  if (print.num) {
    num_str$edge <- as.character(row.names(x$edges))
    num_str$edge[length(num_str$edge)] <- "edge #"
  }
  else {
    col <- col[names(col) != "edge"]
  }
  if (length(col) <= 1) {
    range <- 1
    pos <- 1
    y_offset <- 0
  }
  else if (length(col) <= 3) {
    range <- seq_len(min(3, length(col)))
    pos <- c(2, 4, 1)
    y_offset <- float * wid * c(1, 1, 0)
  }
  else {
    range <- 1:4
    pos <- c(2, 4, 2, 4)
    y_offset <- c(float, float, 0.01, 0.01) * wid * c(1, 
                                                      1, -2, -2)
  }
  for (i in range) {
    name <- names(col)[i]
    text(x = axes[, 2], y = axes[, 1] + y_offset[i], num_str[[name]], 
         col = col[name], pos = pos[i], offset = 0.3, cex = cex, 
         font = font)
  }
}

这里是一个可复制的示例:

library(pvclust)
data(Boston, package = "MASS")
boston.pv <- pvclust(Boston, nboot=100, parallel=FALSE)

plot(as.dendrogram(boston.pv$hclust), horiz=TRUE)

mytext(boston.pv)  # 我们在这里使用了定制的文本函数

返回R上函数[pvclust]的树形图。

英文:

you need to modify the pvclust text function like here mytext is the customized version (you can copy past it)

mytext=function (x, col = c(au = 2, bp = 3, edge = 8), print.num = TRUE, 
float = 0.01, cex = NULL, font = NULL, ...) 
{
if (length(col) == 3 &amp;&amp; is.null(names(col))) 
names(col) &lt;- c(&quot;au&quot;, &quot;bp&quot;, &quot;edge&quot;)
axes &lt;- pvclust:::hc2axes(x$hclust)
usr &lt;- par()$usr
wid &lt;- usr[4] - usr[3]
num_str &lt;- lapply(x$edges[seq_len(which(names(x$edges) == 
&quot;bp&quot;))], function(p) round(p * 100))
for (i in names(num_str)) {
num_str[[i]][length(num_str[[i]])] &lt;- i
}
if (print.num) {
num_str$edge &lt;- as.character(row.names(x$edges))
num_str$edge[length(num_str$edge)] &lt;- &quot;edge #&quot;
}
else {
col &lt;- col[names(col) != &quot;edge&quot;]
}
if (length(col) &lt;= 1) {
range &lt;- 1
pos &lt;- 1
y_offset &lt;- 0
}
else if (length(col) &lt;= 3) {
range &lt;- seq_len(min(3, length(col)))
pos &lt;- c(2, 4, 1)
y_offset &lt;- float * wid * c(1, 1, 0)
}
else {
range &lt;- 1:4
pos &lt;- c(2, 4, 2, 4)
y_offset &lt;- c(float, float, 0.01, 0.01) * wid * c(1, 
1, -2, -2)
}
for (i in range) {
name &lt;- names(col)[i]
text(x = axes[, 2], y = axes[, 1] + y_offset[i], num_str[[name]], 
col = col[name], pos = pos[i], offset = 0.3, cex = cex, 
font = font)
}
}

here a reproducible example :

library(pvclust)
data(Boston, package = &quot;MASS&quot;)
boston.pv &lt;- pvclust(Boston, nboot=100, parallel=FALSE)
plot(as.dendrogram(boston.pv$hclust),horiz=TRUE)
mytext(boston.pv)  # we use the customized text function here 

返回R上函数[pvclust]的树形图。

huangapple
  • 本文由 发表于 2023年2月23日 19:10:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/75544010.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定