【问题标题】:visualization clusters in R (using apcluster)R中的可视化集群(使用apcluster)
【发布时间】:2018-09-07 03:48:02
【问题描述】:

我需要通过模板来可视化我的集群。 我的意思是,这是我的数据。

mydat<- read.csv("mydat.csv",sep=";", dec=",")

输入

  structure(list(x1 = c(0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
    0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L), x2 = c(0L, 0L, 0L, 
    0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 
    0L, 0L), x3 = c(0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
    0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), x4 = c(0L, 0L, 0L, 0L, 0L, 
    0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 0L
    ), x5 = c(0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 
    0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), x6 = c(0L, 0L, 0L, 0L, 0L, 0L, 
    0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 1L, 1L, 1L), 
        x7 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 
        0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L), x8 = c(0L, 0L, 0L, 0L, 0L, 
        0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 
        0L)), .Names = c("x1", "x2", "x3", "x4", "x5", "x6", "x7", 
    "x8"), class = "data.frame", row.names = c(NA, -21L))

我进行了聚类分析

library("apcluster")
apres1 <- apclusterK(negDistMat(r=2), df, K=25)
apres1

我如何可视化结果,集群显示在这张图片中

为 Ken.S 编辑 我试过这样做

plot(apres1, mydat)

但可视化不适合我

我不想要 25 个地块,我想要 1 个地块,就像我执行分类一样

【问题讨论】:

  • @KenS。我编辑了描述的帖子,我做了什么

标签: r ggplot2 package cluster-analysis


【解决方案1】:

选择要绘制的 2 列。

library("apcluster")
for(i in 1:3)
{
x11()
m=i
n=i+1
mehul= iris[,c(m,n)]
apres1 <- apclusterK(negDistMat(r=3),mehul,K=3)
plot(apres1,mehul)
}

【讨论】:

  • 我必须只绘制两列,x1,x2,然后是 x3,x4,然后是 x4,x1,?是否可以写一个循环,让所有列交替绘制..,即会有大量单独的情节。你明白我的想法吗? (1-3,1-5,2-5, 2-3)....
  • 是的,您可以使用 x11() 在新窗口中绘制每个图形并为不同的绘图创建循环
  • 你能用这个循环编辑你的答案给我看,然后我接受你的答案
  • 很高兴回答您的问题。请再给我一些时间。
猜你喜欢
  • 2015-08-07
  • 2018-07-11
  • 2016-12-15
  • 2014-04-18
  • 2020-10-24
  • 1970-01-01
  • 2020-03-30
  • 2020-05-05
  • 1970-01-01
相关资源
最近更新 更多