2

我正在尝试为我的数据集生成一个绘图,可以在此处找到

有 13 个属性,第 13 个属性是类。第一个属性只是 ID,所以我想忽略它。

我尝试像这样创建图表,但出现错误

> ggpairs(wine[2:13], columns=2:12,
+         colour='q', lower=list(continuous='points'),
+         axisLabels='none',
+         upper=list(continuous='blank'))
Error in unit(tic_pos.c, "mm") : 'x' and 'units' must have length > 0
4

1 回答 1

4

首先,您的列错误,然后颜色错误,这就是导致上述错误的原因:

代码应该如下所示,为了更有意义,我将其拆分了一下:

#load data
wine <- read.csv("wine_nocolor.csv")
#remove first column
wine1 <- wine[2:13]
#The colour column needs to be of factor class
wine1$q <- factor(wine1$q)

library(GGally)
#and now you need to pick the correct columns i.e. from 1 to 11 as you don't 
#need the last column
ggpairs(wine1, columns=1:11,
        colour='q',lower=list(continuous='points'),
        axisLabels='none',
        upper=list(continuous='blank'))

将颜色列作为因素并选择正确的列可以得到您想要的输出:

在此处输入图像描述

于 2015-04-02T17:29:50.320 回答