2016-09-22 14 views
-1

私はデータの都市のサンプルを持っており、いくつかのパラメータのためにそれらをクラスタリングしています。しかし、視覚的に表現するのは難しいですが、最初にclusplotを使用しましたが、スケールがなぜ変化するのか理解できません。-1と1の範囲の2つのコンポーネントだけでプロットしても-4から4、 2〜2のようになります(例:1)。クラスタ化されたオブジェクトの名前を表示

[clusplot[1]

だから私はhullplot DBSCANパッケージを使用していますが、そのプロットはclusplotとして、2を参照してください、あなたの出力に都市の名前が表示されません。誰かが私にこれらの名前をグラフに追加する方法の提案をくれますか?

hullplot

+0

プロットを作成するコードを追加してください – rawr

答えて

0

私はこのためにggplot2とggrepelパッケージを使用しようとするだろう。私は凸包を作るためにコードを借用しましたthis question

set.seed(175) 
library(ggplot2) 
library(ggrepel) # Or first install.packages("ggrepel") 

# Make the cluster 
mtcars$cluster <- as.factor(kmeans(mtcars, 3)$cluster) 

# Get the convex hull for the axes you want to plot 
hull_df <- plyr::ddply(mtcars, "cluster", function(dta) { 
    hull <- chull(dta$mpg, dta$disp) 
    dta[c(hull, hull[1]), ] 
}) 

ggplot(mtcars, aes(mpg, disp, color = cluster, fill = cluster)) + 
    geom_point() + 
    geom_polygon(data = hull_df, alpha = 0.5) + 
    geom_text_repel(aes(label = row.names(mtcars))) 

結果:ここで enter image description here

+0

ありがとう、本当に私を助けました! clusplotがどのように機能するかを知っていれば、2つ以上のパラメータでクラスタリングをプロットすることができる唯一の人だからです。また、2つの最も重要なパラメータ、つまり実行中のパラメータのみを使用するため、非常に感謝します。変数の選択のような何か? PCA?! – user2905427

0

はDBSCANでこれを行うにはどのようにいくつかの例は以下のとおりです。

library(dbscan) 
set.seed(2) 
n <- 400 

x <- cbind(
    x = runif(4, 0, 1) + rnorm(n, sd=0.1), 
    y = runif(4, 0, 1) + rnorm(n, sd=0.1), 
    z = runif(4, 0, 1) + rnorm(n, sd=0.1) 
) 
cl <- rep(1:4, time = 100) 

### show some points (first 10) inside the hulls with text 
hullplot(x, cl, main = "True clusters", pch = NA) 
points(x[1:10,]) 
text(x[1:10,], labels = paste("Obs.", 1:10), pos = 3) 

### look at dimensions x and z 
hullplot(x[, c("x", "z")], cl, main = "True clusters") 

### use a PCA projection 
hullplot(prcomp(x)$x, cl, main = "True clusters") 

あなたはもっと良い言葉のレイアウトのためのパッケージwordcloudで見ることができます。 here.

関連する問題