Using multiple scale_colour_gradient scales for different ranges of the data in one plot

后端 未结 1 1703
臣服心动
臣服心动 2021-02-10 11:26

I am very new to R so please bear with me if something is not clear in my question.

I have a data.frame \"protein\" with 5 columns, namely;

1.prote

1条回答
  •  情歌与酒
    2021-02-10 11:51

    For this type of thing you want to use scale_gradientn. For example:

    library(ggplot2)
    
    x = seq(-0.1, 0.1, len=100)
    y = 0:10
    dat = expand.grid(x=x, y=y)
    
    ggplot(data=dat, aes(x=x, y=y, fill=x)) +
      geom_raster() +
      scale_fill_gradientn(colours=c('red', 'yellow', 'cyan', 'blue'),
        values   = c(-0.05,-1e-32,1e-32,0.05),
        breaks   = c(-0.05,-0.005,0.005,0.05),
        rescaler = function(x,...) x,
        oob      = identity)
    

    enter image description here

    0 讨论(0)
提交回复
热议问题