Error message when using ggcorrplot() and cor_pmat()

682 views Asked by At

I have trouble with the following code:

library(ggplot2)
library(ggcorrplot)
data(USArrests)
correlation_matrix <- round(cor(USArrests),1)
corrp.mat <- cor_pmat(USArrests)
ggcorrplot(correlation_matrix, hc.order =TRUE, type ="lower", 
           p.mat = corrp.mat)

When I run the code, execution stops at ggcorrplot(...) and I get this error:

"Error in Math.data.frame(x = list(Assault = c(0.0695, 1.36e-07, 2.6e-12, : non-numeric-alike variable(s) in data frame: rowname"

I tried to run the code in an online R runner and it worked, but in RStudio it doesn´t.

I have no clue whats going on, has somebody an idea?

1

There are 1 answers

0
Sev On

Thank you @Quinten for your suggestion. Unloading the unnecessary packages helped. The package rstatix seemed to interfere with the cor_pmat() command.