【问题标题】:Is there a way that I can solve or stop this error problem in cardinality_threshold?有没有办法可以解决或停止 cardinality_threshold 中的这个错误问题?
【发布时间】:2021-08-15 13:45:33
【问题描述】:

我想将大约 17 个土壤变量与海拔、温度和降雨量与物种丰富度和丰度进行关联。我有 39 个图(行),列包含环境变量,例如海拔、丰度、物种丰富度、温度、降雨量,然后是土壤变量列表(17 列)。下面是我的脚本。

我的脚本有问题还是我使用的 Mac 的笔记本电脑兼容性问题?请帮忙。谢谢

运行代码后,我收到此错误:

stop_if_high_cardinality 中的错误(数据、列、cardinality_threshold):

“pH”列的水平 (24) 多于允许的阈值 (15)。 请删除该列或增加“cardinality_threshold”参数。增加 cardinality_threshold 可能会产生较长的处理时间

  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()
  )```

【问题讨论】:

    标签: correlation ggally ggpairs ggsave


    【解决方案1】:

    此错误是内置停止,因为默认参数设置为仅允许在一个图表中显示 15 个级别的变量。您的一个变量有 24 个级别,因此您可以将参数(即 cardinality_threshold)调整为该值 24 或将其设置为 NULL。如果 24 的值并不总是相同,则 Null 可能更通用。但一般来说,一次描绘的水平数会被阻止,并有这些止损限制。

    library(GGally)
    
    data(iris)
    

    创建因子超过 15 个级别的数据

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

    只是证明任何一个条目都可以工作

    ggpairs(iris, cardinality_threshold = 16) 
    
    ggpairs(iris, cardinality_threshold = NULL)
    

    【讨论】:

      猜你喜欢
      • 2020-12-13
      • 2022-09-27
      • 2021-06-03
      • 2021-09-06
      • 2022-06-11
      • 1970-01-01
      • 2020-02-09
      • 2021-05-28
      相关资源
      最近更新 更多