Search code examples
rr-corrplot

How can I change the transparency of a corrplot in R?


I am working in R and I am using the library corrplot.

I would like to change the transparency of the corrplot, something similar to controlling the alpha parameter in ggplot.

An example of the code I am using is:

x <- rnorm(100,0,1)
y <- rnorm(100,0,1)
z <- rnorm(100,0,1)
cor0 <- cor(cbind(x,y,z))
corrplot::corrplot(cor0, "square")

Any idea how to achieve this?


Solution

  • One possibility would be to set the colors yourself and their transparency using scales::alpha:

    library(scales)
    
    colors <- scales::alpha(colorRampPalette(c("white", "red"))(10), alpha = 0.3)
    
    corrplot::corrplot(cor0, "square", col = colors)
    

    enter image description here