Search code examples
rr-corrplot

Corrplot output format


I am currently trying to fix the visual output of a generated Corrplot but have so far been unsuccessful with two things:

  1. The title always gets chopped off the top

  2. I can't change the color of the labels from red to black

    A <- seq(1, 100, by=1)
    B <- sample(A,100, replace =T)
    C <- sample(A,100, replace =T)
    D <- sample(A,100, replace =T)
    E <- sample(A,100, replace =T)
    sample(A,100, replace =T)
    X <- data.frame(A,B,C,D,E)
    
    X <- cor(X, method = c("spearman"))
    
    corrplot(X,
     method = "circle",
     type = "upper",
     diag = F,
     addCoef.col=T,
     title = "Testing")
    

Additionally, is it possible to just keep the first 2 variables (i.e A and B) and show the correlation horizontal with every other parameter C-E? Thanks for the pointers!


Solution

  • To keep the title from being truncated, use the mar parameter.
    To adjust the color of the labels, use the tl.col parameter.
    To have a horizontal display that only shows (A,B) by (C,D,E), get rid of type="upper" and diag=F,
    add is.corr=F and then just use the part of the matrix that you want X[1:2,3:5].

    Putting that all together, we get

    corrplot(X[1:2,3:5],
     is.corr=FALSE,
     method = "circle",
     addCoef.col=T,
     mar=c(0,0,5,0),
     tl.col = "black",
     title = "Testing")
    

    Adjusted corrplot