2d color gradient plot in R

后端 未结 4 514
既然无缘
既然无缘 2020-12-09 20:25

I want to produce a 2d color gradient rectangle like the ones in the picture below on the right hand side. How can I do this in R? Using colorRamp or RCol

4条回答
  •  攒了一身酷
    2020-12-09 20:55

    you may try this and see result plot

    rotate <- function(x) t(apply(x, 2, rev))
    n <- 3
    library(grid)
    mm <- tcrossprod(seq(1,0,length.out = n))
    tmp1 <- sapply(col2rgb("orange")/255, function(x) 1-mm*(1-x))
    tmp2 <- sapply(col2rgb("cyan")/255, function(x) 1-rotate(mm)*(1-x))
    tmp3 <- sapply(col2rgb("purple")/255, function(x) 1-rotate(rotate(mm))*(1-x))
    tmp4 <- sapply(col2rgb("grey")/255, function(x) 1-rotate(rotate(rotate(mm)))*(1-x))
    
    tmp <- (tmp1*tmp2*tmp3*tmp4)
    grid.raster(matrix(rgb(tmp), nrow = n))
    

    result plot < click it to see

提交回复
热议问题