% set("branches_lwd", 1.2) %>% as.gg-6ren">
gpt4 book ai didi

r - 如何在R中的树状图中旋转ylab标签?

转载 作者:行者123 更新时间:2023-12-04 08:02:59 25 4
gpt4 key购买 nike

df <- scale(mtcars) # Standardize the data

library("factoextra")
library("cluster")

dist <- dist(df, method = "euclidean") # df = standardized data
hc <- hclust(dist, method = "ward.D2")

fviz_dend(hc, k = 4, # Cut in four groups
cex = 0.6, # label size
k_colors = "jco",
color_labels_by_k = TRUE, # color labels by groups
rect = TRUE, # Add rectangle around groups
rect_border = "jco",
rect_fill = TRUE,
rotate = TRUE)
你好,新手,我的问题是;
  • 我想要顺时针方向的树状图,如下图所示,如何在树状图中制作水平 ylab 标签
  • 如何减少轴刻度和轴标签之间的空间
    我用过mtcars数据

  • enter image description here

    最佳答案

    按照我的上述问题,我找到了在树状图中旋转 ylab 标签的代码。在这里发帖,可能对其他人有用。

    library("ggdendro", "dendextend")
    ggdendrogram(hc) + theme_minimal(16) +
    coord_flip() +
    theme(panel.grid.major.y = element_blank(),
    panel.grid.minor.y = element_blank())

    library(dendextend)
    hc %>%
    as.dendrogram %>%
    set("branches_k_color", k = 3) %>%
    set("branches_lwd", 1.2) %>%
    as.ggdend( ) %>%
    ggplot(horiz=TRUE,
    offset_labels = -2.8 ) +
    theme_minimal(16) +
    labs(x = "Y",
    y = "X") +
    scale_y_continuous(position = "left") +
    theme(axis.text.y = element_blank(),
    panel.grid.major.y = element_blank(),
    panel.grid.minor.y = element_blank())
    enter image description here

    关于r - 如何在R中的树状图中旋转ylab标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66357424/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com