I am trying to order the variables in the parallel coordinate plot as below. But it throws an error and I am not so sure what causes this problem.
library(GGally)
library(palmerpenguins)
penguins %>% ggparcoord(columns = 3:4, groupColumn = 1, order = "anyClass")
The error says
Error in model.frame.default(formula = x ~ as.factor(classVar == class.names[i]), : variable lengths differ (found for 'as.factor(classVar == class.names[i])')
The issue seems to be related to the fact that your columns=
contain missings. One possible fix would be to manually drop the observations with missings before passing to ggparcoord
:
library(GGally)
#> Loading required package: ggplot2
#> Registered S3 method overwritten by 'GGally':
#> method from
#> +.gg ggplot2
library(palmerpenguins)
penguins %>%
tidyr::drop_na(3:4) |>
ggparcoord(columns = 3:4, groupColumn = 1, order = "anyClass")