R GGALY中出错-确保您的';列';值小于5

R GGALY中出错-确保您的';列';值小于5,r,cluster-analysis,k-means,ggally,R,Cluster Analysis,K Means,Ggally,我正在尝试使用GGally包绘制iris数据集 > 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 gg

我正在尝试使用
GGally
包绘制iris数据集

> 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-means,然后将结果与实际结果进行比较,但这也会产生类似的错误:

> 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)
>设置种子(1234)
>iris$Cluster ggpairs(iris,columns=c(“萼片长度”、“萼片宽度”、“花瓣长度”、“花瓣宽度”)、color='Cluster',lower=list(continuous='points')、axisLabels='none',upper=list(continuous='blank'))
成对错误(虹膜,列=c(“萼片长度”、“萼片宽度”、“花瓣长度”),:
确保“列”值小于6。
列=c(萼片长度,萼片宽度,花瓣长度,花瓣宽度)

错误在于columns参数,该参数必须是索引向量,即:

#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'))
输出:

对于
kmeans
plot,情况完全相同:

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'))
set.seed(1234)

iris$Cluster谢谢!这很有效,但我现在无法将其应用于我的数据集。我为此问了一个单独的问题,谢谢!很高兴我能提供帮助:)。我也回复了你的其他帖子,给你一个解决方案:)我如何指定列,例如在16列中我想要5,8,10?
columns=c(5,8,10)
应该可以。如果没有,试着问一个新问题。