Search code examples
rggally

Using column names in ggparcoord


I have a really basic problem with ggparcoord plot function from Ggally package. On this site https://r-graph-gallery.com/parallel-plot-ggally.html there is the following code for the "most basic" plot, which works fine:

# Libraries
library(GGally)

# Data set is provided by R natively
data <- iris

# Plot
ggparcoord(data,
    columns = 1:4, groupColumn = 5
    )

I'm just not able to use the column names instead and to use a specific order like:

# Libraries
library(GGally)

# Data set is provided by R natively
data <- iris

# Plot
ggparcoord(data,
    columns = c('Petal.Width', 'Sepal.Width', 'Petal.Length', 'Sepal.Length'), groupColumn = 'Species',
    )

I get the error: "invalid value for order; must either be a vector of column indices or one of 'skewness', 'allClass' ..."

I found a solution with column indices to use something like

columns = c(4, 2, 3, 1)

Is there no standard way to use column names for this plot?

Thank you!


Solution

  • While both column names and indices actually should work in current {GGally} versions, you could use match for a workaround:

    match(c('Petal.Length', 'Sepal.Length'),
          names(iris)
    )
    
    [1] 3 1