Search code examples
rr-corrplot

Extract the order list from an ordered correlation matrix: R


I created a correlation matrix and visualize it using the corrplot function with the following code

temp<-matrix(rexp(25, rate=.1), ncol=5)
tempCor<-cor(temp)
tempCor <- data.frame(tempCor)
names(tempCor) <- c(1:5)
corrplot(t(tempCor),method="pie",order="AOE")

Here is the result of the corrplot funciton

plot

Is there any way to get the order list from this result, which is (4,5,1,3,2)?


Solution

  • Try this:

    library(corrplot)
    set.seed(1234)
    temp <- matrix(rexp(25, rate=.1), ncol=5)
    tempCor <- cor(temp)
    tempCor <- data.frame(tempCor)
    names(tempCor) <- c(1:5)
    out <- corrplot(t(tempCor),method="pie",order="AOE")
    dimnames(out)
    

    Here is what you are looking for:

    [[1]]
    [1] "5" "1" "3" "4" "2"
    
    [[2]]
    [1] "1" "2" "3" "4" "5"