英文:
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).
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) # 我们在这里使用了定制的文本函数
英文:
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 && 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)
}
}
here a reproducible example :
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) # we use the customized text function here
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论