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

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

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是定制版本一样(你可以复制粘贴它)

  1. mytext = function (x, col = c(au = 2, bp = 3, edge = 8), print.num = TRUE,
  2. float = 0.01, cex = NULL, font = NULL, ...)
  3. {
  4. if (length(col) == 3 && is.null(names(col)))
  5. names(col) <- c("au", "bp", "edge")
  6. axes <- pvclust:::hc2axes(x$hclust)
  7. usr <- par()$usr
  8. wid <- usr[4] - usr[3]
  9. num_str <- lapply(x$edges[seq_len(which(names(x$edges) ==
  10. "bp")], function(p) round(p * 100))
  11. for (i in names(num_str)) {
  12. num_str[[i]][length(num_str[[i]])] <- i
  13. }
  14. if (print.num) {
  15. num_str$edge <- as.character(row.names(x$edges))
  16. num_str$edge[length(num_str$edge)] <- "edge #"
  17. }
  18. else {
  19. col <- col[names(col) != "edge"]
  20. }
  21. if (length(col) <= 1) {
  22. range <- 1
  23. pos <- 1
  24. y_offset <- 0
  25. }
  26. else if (length(col) <= 3) {
  27. range <- seq_len(min(3, length(col)))
  28. pos <- c(2, 4, 1)
  29. y_offset <- float * wid * c(1, 1, 0)
  30. }
  31. else {
  32. range <- 1:4
  33. pos <- c(2, 4, 2, 4)
  34. y_offset <- c(float, float, 0.01, 0.01) * wid * c(1,
  35. 1, -2, -2)
  36. }
  37. for (i in range) {
  38. name <- names(col)[i]
  39. text(x = axes[, 2], y = axes[, 1] + y_offset[i], num_str[[name]],
  40. col = col[name], pos = pos[i], offset = 0.3, cex = cex,
  41. font = font)
  42. }
  43. }

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

  1. library(pvclust)
  2. data(Boston, package = "MASS")
  3. boston.pv <- pvclust(Boston, nboot=100, parallel=FALSE)
  4. plot(as.dendrogram(boston.pv$hclust), horiz=TRUE)
  5. 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)

  1. mytext=function (x, col = c(au = 2, bp = 3, edge = 8), print.num = TRUE,
  2. float = 0.01, cex = NULL, font = NULL, ...)
  3. {
  4. if (length(col) == 3 &amp;&amp; is.null(names(col)))
  5. names(col) &lt;- c(&quot;au&quot;, &quot;bp&quot;, &quot;edge&quot;)
  6. axes &lt;- pvclust:::hc2axes(x$hclust)
  7. usr &lt;- par()$usr
  8. wid &lt;- usr[4] - usr[3]
  9. num_str &lt;- lapply(x$edges[seq_len(which(names(x$edges) ==
  10. &quot;bp&quot;))], function(p) round(p * 100))
  11. for (i in names(num_str)) {
  12. num_str[[i]][length(num_str[[i]])] &lt;- i
  13. }
  14. if (print.num) {
  15. num_str$edge &lt;- as.character(row.names(x$edges))
  16. num_str$edge[length(num_str$edge)] &lt;- &quot;edge #&quot;
  17. }
  18. else {
  19. col &lt;- col[names(col) != &quot;edge&quot;]
  20. }
  21. if (length(col) &lt;= 1) {
  22. range &lt;- 1
  23. pos &lt;- 1
  24. y_offset &lt;- 0
  25. }
  26. else if (length(col) &lt;= 3) {
  27. range &lt;- seq_len(min(3, length(col)))
  28. pos &lt;- c(2, 4, 1)
  29. y_offset &lt;- float * wid * c(1, 1, 0)
  30. }
  31. else {
  32. range &lt;- 1:4
  33. pos &lt;- c(2, 4, 2, 4)
  34. y_offset &lt;- c(float, float, 0.01, 0.01) * wid * c(1,
  35. 1, -2, -2)
  36. }
  37. for (i in range) {
  38. name &lt;- names(col)[i]
  39. text(x = axes[, 2], y = axes[, 1] + y_offset[i], num_str[[name]],
  40. col = col[name], pos = pos[i], offset = 0.3, cex = cex,
  41. font = font)
  42. }
  43. }

here a reproducible example :

  1. library(pvclust)
  2. data(Boston, package = &quot;MASS&quot;)
  3. boston.pv &lt;- pvclust(Boston, nboot=100, parallel=FALSE)
  4. plot(as.dendrogram(boston.pv$hclust),horiz=TRUE)
  5. 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:

确定