Search code examples
rplotggally

Error in GGally: Error in unit(tic_pos.c, "mm") : 'x' and 'units' must have length > 0


I'm trying to generate a plot for my dataset that can be found here

There are 13 attributes with 13th attribute being the class. The first attribute is just ID so I want to ignore it.

I try to create the graph like this but I'm getting an error

> 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

Solution

  • First of all you have the columns wrong and then you got the colour wrong which is what gives the above error:

    The code should be like the following and I split it up a bit to make more sense:

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

    Having the colour column as factor and picking the correct columns gives the output you want:

    enter image description here