ggscatmat plots in GGally not working with increasing col numbers

I've been working with ggscatmat from the GGplot library to generate plots of a correlation matrix. I am running into two problems/questions:

  1. When I increase the column number in the plots to go beyond 9, the formatting of the plots gets messed up. Is there a hard limit to the pairs of columns I can compare?

  2. I'm getting a warning that Factor variables are omitted in plot. However, all columns in the dataset are numeric, so I am puzzled why this warning appears.

Any thoughts?

#// load GGally library
library(GGally)
#> Loading required package: ggplot2
#> Registered S3 method overwritten by 'GGally':
#>   method from   
#>   +.gg   ggplot2

#// generate datafram
data <- data.frame(rep(mtcars[1:5], 3))

#// ggscatmat with increasing column numbers
ggscatmat(data[1:5],  columns = 1:5,  color = "cyl", alpha  = 0.8)

#> Warning in ggscatmat(data[1:5], columns = 1:5, color = "cyl", alpha = 0.8):
#> Factor variables are omitted in plot

[new user only allowed 1 plot per post]

ggscatmat(data[1:10], columns = 1:10, color = "cyl", alpha  = 0.8)

#> Warning in cor(xvalue, yvalue, use = "pairwise.complete.obs", method =
#> corMethod): the standard deviation is zero

[...]

#> Warning in ggscatmat(data[1:10], columns = 1:10, color = "cyl", alpha = 0.8):
#> Factor variables are omitted in plot

[new user only allowed 1 plot per post]

ggscatmat(data[1:15], columns = 1:15, color = "cyl", alpha  = 0.8)

#> Warning in cor(xvalue, yvalue, use = "pairwise.complete.obs", method =
#> corMethod): the standard deviation is zero

[...]

#> Warning in ggscatmat(data[1:15], columns = 1:15, color = "cyl", alpha = 0.8):
#> Factor variables are omitted in plot

Created on 2021-01-29 by the reprex package (v0.3.0)

ggscatmat() is a faster version of ggpairs(), but due to some internal trickery, it is a little brittle.


Can you try using ggpairs() for your plot?

I think your code could be:

library(dplyr)

data %>% 
  # turn cyl into factor, since it is treated as a factor
  mutate(cyl = as.factor(cyl)) %>% 
  ggpairs(columns = 1:15, mapping = aes(color = cyl))

1 Like

Sweet. Thank you. I'll just use ggpairs.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.