[英]How can I interpret the meaning of this error when trying to compute a correlation matrix?
我一直在嘗試制作我認為應該是一個簡單的相關矩陣。 我有以下數據:
cormetric2 <- structure(list(rich = c(24.03017241, 22.3), spatial = c(20.16163793, 18.71), abund = c(13.69612069, 12.71),
rare = c(12.14439655, 11.27), div = c(8.265086207, 7.67), nature = c(8.006465517, 7.43 ),
other = c(7.747844828, 7.19), endem = c(3.362068966, 3.12), agm = c(2.068965517, 1.92),
umbsp = c(0.517241379, 0.48)), class = "data.frame", row.names = c("GlobalOld", "GlobalNew"))
我使用了以下代碼:
corrplot(cormetric2, type = "upper", order = "hclust",
tl.col = "black", tl.srt = 45)
corrplot(cormetric2, type="upper")
兩者都返回以下錯誤消息:
if (any(corr < cl.lim[1]) || any(corr > cl.lim[2])) {: 需要 TRUE/FALSE 的缺失值
這個錯誤信息是什么意思? 我的數據集中沒有任何零,如下所示:
head(cormetric2)
rich spatial abund rare div nature other endem agm umbsp
GlobalOld: 24.03017 20.16164 13.69612 12.1444 8.265086 8.006466 7.747845 3.362069 2.068966 0.5172414
GlobalNew: 22.30000 18.71000 12.71000 11.2700 7.670000 7.430000 7.190000 3.120000 1.920000 0.4800000
如何創建關聯 plot?
默認情況下, corrplot
檢查corr
object 作為相關矩陣。 根據輸入,它不是相關矩陣,甚至不是矩陣。 它是一個data.frame
。 我們可以使用as.matrix
轉換為matrix
,並根據?corrplot
的文檔指定is.corr = FALSE
corr - 要可視化的相關矩陣,如果 order 不是“原始”,則必須是正方形。 對於一般矩陣,請使用 is.corr = FALSE 進行轉換。
library(corrplot)
corrplot(as.matrix(cormetric2), is.corr = FALSE, type = "upper")
-輸出
cormetric2 <- structure(list(rich = c(24.03017241, 22.3),
spatial = c(20.16163793,
18.71), abund = c(13.69612069, 12.71), rare = c(12.14439655,
11.27), div = c(8.265086207, 7.67), nature = c(8.006465517, 7.43
), other = c(7.747844828, 7.19), endem = c(3.362068966, 3.12),
agm = c(2.068965517, 1.92), umbsp = c(0.517241379, 0.48)),
class = "data.frame", row.names = c("GlobalOld",
"GlobalNew"))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.