user2917781
user2917781

Reputation: 291

Change orientation of diagonal of correlation plot using ggcorrplot package

I am trying to use the ggcorrplot package in R to make a correlation matrix. However, the diagonal in the resulting plot is different than the input correlation matrix.

For example, here is a basic plot using the package:

library(ggcorrplot)
data(mtcars)
corr.mat <- cor(mtcars[, c("mpg", "disp", "hp", "drat", "wt", "carb")])
ggcorrplot(corr.mat)

This plot has a diagonal going up the matrix from left to right. Instead, I want the resulting plot to look exactly like the correlation matrix that I used as an input:

print(corr.mat)

That is, the correlation for the mpg variable should be at position [1,1] in the matrix.

Upvotes: 4

Views: 1298

Answers (1)

user2554330
user2554330

Reputation: 44887

You can do it by reversing the rows or columns of corr.mat:

ggcorrplot(corr.mat[,6:1])

gives

enter image description here

Upvotes: 4

Related Questions