【问题标题】:Visualizing the CLARA cluster center/medoid可视化 CLARA 集群中心/中心点
【发布时间】:2021-11-24 05:17:31
【问题描述】:

我使用 fviz_cluster (ggplot2) 可视化了我的 CLARA 结果,我希望每个集群的中心点比其他数据点更突出(比如改变它们的形状或颜色等)。问题是,我有超过 800,000 个数据点,仅通过“show.clust.cent”是不可能看到的。

我怎样才能用不同的颜色为中心点着色,使它们比其他数据点大得多,或者使除了中心点之外的其他数据点不可见?我也尝试使用 star.plot 但不知何故它不起作用。

我知道 medoids 的行号,想手动添加,但我也不知道如何将它集成到 fviz_cluster。

谁能帮我解决这个问题?谢谢!

fviz_cluster(clara.res,
         palette = c("#004c6d",
                     "#00ffff",
                     "#00a1c1",
                     "#6efa75",
                     "#78ab63",
                     "#cc0089",
                     "#ffc334",
                     "#ff9509",
                     "#ffb6de",
                     "#00cfe3"
                      ), # color palette
         ellipse.type = "t",geom = "point",show.clust.cent = TRUE,repel = TRUE,pointsize = 0.5,
         ggtheme = theme_classic()

【问题讨论】:

    标签: r ggplot2 cluster-analysis cluster-computing k-means


    【解决方案1】:

    这对你来说可以吗?

    library(tidyverse)
    
    fpoint = function(n) tibble(
      Dlm1 = rnorm(n, sample(-20:20,1), sample(1:5,1)),
      Dlm2 = rnorm(n, sample(-20:20,1), sample(1:5,1))
    )
    
    df = tibble(cluster = paste(1:10)) %>% 
      mutate(data = map(cluster, ~fpoint(1000))) %>% 
      unnest(data)
    
    df %>% ggplot(aes(Dlm1, Dlm2, color=cluster))+
      geom_point(alpha = 0.2, pch=21)+
      stat_ellipse(size=0.7)
    

    将数据写入tibble并使用标准ggplot

    更新 1

    library(factoextra)
    library(cluster)
    df = USArrests %>%  na.omit() %>% scale()
    kmed = pam(df, k = 4)
    fviz_cluster(kmed, data = df, alpha=0.3, geom = "point", show.clust.cent = TRUE,repel = TRUE, pointsize = 2)
    

    这就是重点吗?

    【讨论】:

    • 嗨,Marek,不,不幸的是,我仍然无法看到带有这个的 medoids :(
    • 你看到我的更新了吗?通过适当地设置alpha 参数(用于点),您将能够毫无问题地看到中间体。这能解决您的问题吗?
    猜你喜欢
    • 2021-10-16
    • 2016-10-27
    • 1970-01-01
    • 1970-01-01
    • 2010-11-18
    • 2016-04-10
    • 2018-07-03
    • 2013-05-04
    • 2017-09-24
    相关资源
    最近更新 更多