我已经创建了一个带有heatmaply的树状图,其中包含来自dendextend包的树状图对象。我想知道是否有一种方法可以改变列的顺序: vs、am、carb、wt、drat、gear等。例如,我想按字母顺序对它们进行排序。这个是可能的吗?
library(heatmaply)
library(tidyverse)
library(RColorBrewer)
library(dendextend)
custom_colors <- c("#B6E2D3", "#887BB0", "#FFD53D", "#EF7C8E", "#A1F7A1", "#EFE7BC", "#C26DBC", "#14C2DD",
"#5CD85A", "#AB6B51", "#39918C", "#FFA384", "#57DDF3", "#D0B49F", "#EEB5EB", "#74BDCB")
dend_example <- mtcars %>% dist %>% hclust(method = "ward.D2") %>%
as.dendrogram %>% color_branches(k=5) %>% color_labels
heatmaply_mtcars<- heatmaply(mtcars, hclustfun = hclust, hclust_method = "ward.D2",
Rowv = dend_example,
main = "mtcars",
show_dendrogram = c(TRUE, FALSE),
showticklabels = c(TRUE, TRUE),
scale_fill_gradient_fun = ggplot2::scale_fill_gradient2(high = "#025492"),
file = "heatmaply_mtcars.html",
column_text_angle = 30,
colorbar_thickness = 50)

发布于 2020-12-10 06:41:30
我在heatmaply中包含了一个带有colv参数的柱状树状图。使用来自包dendextend的旋转函数旋转柱状树状图:
dend_example <- mtcars %>% dist %>% hclust(method = "ward.D2") %>%
as.dendrogram %>% color_branches(k=5) %>% color_labels
column_dend <- t(mtcars) %>% dist %>% hclust(method = "ward.D2") %>%
as.dendrogram
column_dend <- column_dend %>% rotate(c(vector_with_labels))
heatmaply_mtcars<- heatmaply(mtcars, hclustfun = hclust, hclust_method = "ward.D2",
Rowv = dend_example,
Colv = column_dend,
main = "mtcars",
show_dendrogram = c(TRUE, FALSE),
showticklabels = c(TRUE, TRUE),
scale_fill_gradient_fun = ggplot2::scale_fill_gradient2(high = "#025492"),
file = "heatmaply_mtcars.html",
column_text_angle = 30,
colorbar_thickness = 50)https://stackoverflow.com/questions/65134851
复制相似问题