GGally错误:单位错误(tic_pos.c,“mm”):'x'和'units'必须有长度> 0

时间:2015-04-02 17:05:26

标签: r plot ggally

我试图为我的数据集生成一个可以找到的图here

有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

1 个答案:

答案 0 :(得分: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'))

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

enter image description here