GGally 中的错误 - 确保您的 'columns' 值小于 5

Error in GGally - Make sure your 'columns' values are less than 5

我正在尝试使用 GGally

绘制鸢尾花数据集
> 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)

错误在于 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情节完全一样:

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'))