【发布时间】:2021-02-12 15:33:52
【问题描述】:
我正在寻找一种方法来条件格式化flextable 中的相关矩阵,以便在给定特定值(例如 .5)的情况下突出显示高于该值的单元格。我已经查看了以前关于 SO 的条件格式问题,但无法实施解决方案。这是我的代表,它最终突出了所有单元格:
my_data <- mtcars[, c(1,3,4,5,6,7)] #data
res <- cor(my_data) #initial correlation matrix
res[upper.tri(res)] <- NA # erase the upper triangle
diag(res) <- NA
res %>%
as.data.frame() %>%
rownames_to_column("var") %>%
flextable::flextable() %>%
flextable::bg(i = rownames(res) > .5, j = 2:ncol(res), bg = "light blue")
【问题讨论】: