Is there a way that I can solve or stop this error problem in cardinality_threshold?

760 views Asked by At

I have about 17 soil variables that I'd like to run correlations with elevations, temperature and rainfall against species richness and abundance. I have 39 plots (rows) and the columns contain, environmental variables such as elevation, abundance, species richness, temperature, rainfall and then the list of soil variables (17 columns). Below is my script.

Is there a problem with my script or is it the laptop compatibility of the mac I am using? Please help. Thanks

After running the codes, I am getting this error:

Error in stop_if_high_cardinality(data, columns, cardinality_threshold) :

Column 'pH' has more levels (24) than the threshold (15) allowed. Please remove the column or increase the 'cardinality_threshold' parameter. Increasing the cardinality_threshold may produce long processing times

  GGally::ggpairs(
    na.omit(nfi_nontree_soilclim_data[, c(11:18)]),
    upper = list(
      continuous = wrap(
        custom_ggally_cor,
        method = "spearman", exact = FALSE,
        size = 2.5, col = "black", family = "serif", digits = 2
      ), combo = "box_no_facet", discrete = "count", na = "na"
    ),
    lower = list(
      continuous = wrap(
        ggally_smooth,
        method = "loess", formula = y ~ x,
        se = F, lwd = 3, col = "red", shrink = T
      ), combo = "facethist", discrete = "facetbar", na = "na"
    ),
    diag = list(
      continuous = wrap(
        ggally_densityDiag,
        col = "darkgrey", lwd = .1,
        stat = "density", fill = "darkgrey"
      ), continuous = "densityDiag", na = "naDiag"
    ), axisLabels = c("show")
  ) + theme_bw() + theme(
    text = element_text(family = "serif", size = 4),
    axis.text = element_text(family = "serif", size = 4),
    panel.grid = element_blank()
  )```
1

There are 1 answers

0
Jonni On

This error is a built-in stop because the default parameter is set to only allow 15 levels of a variable to be displayed in one graph. You have 24 levels for one of your variables, so you can either adjust the parameter, i.e., the cardinality_threshold, to that value of 24 or set it to NULL. Null may be more generalizable if the value of 24 isn't always the same. But in general, that number of levels depicted at once is going to be discouraged and have these stop-limits.

library(GGally)

data(iris)

Create data that has factor of more than 15 levels

iris$group = as.factor(sample(sample(letters,16), 150, replace = TRUE))

Just demonstrating that either entry can work

ggpairs(iris, cardinality_threshold = 16) 

ggpairs(iris, cardinality_threshold = NULL)