corrplot: using scaled values for color and size and raw values for legend

31 Views Asked by At
library(corrplot)

v = c(10, 25, 50, 80, 100, 125, 200, 400, 1000)
mat <- matrix(v, ncol = 3)

corrplot(mat, is.corr = FALSE, col = COL2("RdBu"))

I got index values. A value of 100 is average, 150 is 1.5 times base and so on. I would like to plot them in a way that color and circle size are proportional to their factor (base 100). Index 50 should have the same circle size as index 200 (not as 150) and index 100 should be white with circle size 0. I would like the legend to be centered around index 100 but display the raw values.

I can scale the values, but I can't seem to figure out how to get the legend to display the raw values.

size_trans <- function(x) {
  if(x>100){
    return(x/100)
  }
  if(x<100){
    return(-100/x)
  }
  return(0)
}
scaled_mat <- apply(mat, c(1, 2), size_trans)

corrplot(scaled_mat, is.corr = FALSE, col = COL2("RdBu"))

I started disabling the legend and to build one with a combination of a geometric sequence and colorRampPalette() but there might be a simpler solution...?

0

There are 0 best solutions below