Reputation: 1
I have been trying to make what I thought should be a simple correlation matrix. I have the following data:
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"))
I have used the following code:
corrplot(cormetric2, type = "upper", order = "hclust",
tl.col = "black", tl.srt = 45)
corrplot(cormetric2, type="upper")
Both returned the following error message:
Error in if (any(corr < cl.lim[1]) || any(corr > cl.lim[2])) { : missing value where TRUE/FALSE needed
What is the meaning of this error message? I do not have any zeros in my dataset, which looks like this:
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
How can I create the correlation plot?
Upvotes: 0
Views: 719
Reputation: 886938
By default, the corrplot
, checks the corr
object as a correlation matrix. Based on the input, it is not a correlation matrix or even a matrix. It is a data.frame
. We could convert to matrix
with as.matrix
and specify is.corr = FALSE
based on the documentation of ?corrplot
corr - The correlation matrix to visualize, must be square if order is not "original". For general matrix, please using is.corr = FALSE to convert.
library(corrplot)
corrplot(as.matrix(cormetric2), is.corr = FALSE, type = "upper")
-output
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"))
Upvotes: 3