2015-04-02 15 views
3

我試圖使用GGally錯誤GGally - 確保你的「列」的值都小於5

> library(GGally) 
> ggpairs(iris, columns=c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width"), colour='Species', lower=list(continuous='points'), axisLabels='none', upper=list(continuous='blank')) 
Error in ggpairs(iris, columns = c("Sepal.Length", "Sepal.Width", "Petal.Length", : 
    Make sure your 'columns' values are less than 5. 
    columns = c(Sepal.Length, Sepal.Width, Petal.Length, Petal.Width) 

繪製虹膜數據集爲什麼抱怨列值的數量。它不能用於超過5列嗎?

我也想運行K-均值,然後將結果與實際比較,但這也給出了類似的錯誤:

> set.seed(1234) 
> iris$Cluster <- factor(kmeans(iris[,c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width")], centers=length(levels(iris$Species)))$cluster) 
> ggpairs(iris, columns=c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width"), colour='Cluster', lower=list(continuous='points'), axisLabels='none', upper=list(continuous='blank')) 
Error in ggpairs(iris, columns = c("Sepal.Length", "Sepal.Width", "Petal.Length", : 
    Make sure your 'columns' values are less than 6. 
    columns = c(Sepal.Length, Sepal.Width, Petal.Length, Petal.Width) 

回答

2

錯誤在於列參數,它必須是索引的矢量即:

#notice the columns argument is a vector of indices 
library(GGally) 
ggpairs(iris, columns=1:4, 
     colour='Species', lower=list(continuous='points'), 
     axisLabels='none', 
     upper=list(continuous='blank')) 

輸出:

enter image description here

kmeans情節完全一樣:

set.seed(1234) 
iris$Cluster <- factor(kmeans(iris[,c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width")], centers=length(levels(iris$Species)))$cluster) 
ggpairs(iris, columns=1:4, colour='Cluster', lower=list(continuous='points'), axisLabels='none', upper=list(continuous='blank')) 
+0

謝謝!這有效,但我現在無法將其應用於我的數據集。我問了一個單獨的問題http://stackoverflow.com/questions/29418515/error-in-ggally-error-in-unittic-pos-c-mm-x-and-units-must-have-leng謝謝! – Anthony 2015-04-02 17:05:35

+0

我很高興能有所幫助:)。我回復了你的其他帖子以及給你一個解決方案:) – LyzandeR 2015-04-02 17:31:27

+0

如何指定列,例如16列中的我想要5,8,10? – RezaRahmati 2017-12-31 00:27:18

相關問題