Heatmap with continuous rainbow colours

前端 未结 3 1988
执笔经年
执笔经年 2021-01-21 13:04

First of all I have to say that I read many threads about heatmap and ggplot2 here in stackoverflow and elsewhere. But my problem isn\'t solved yet.

I have got the foll

3条回答
  •  北荒
    北荒 (楼主)
    2021-01-21 13:48

    The problem of interpolating colors with a complex color scale is best illustrated on the "old faithful" data.

    If you use your user defined "rainbow" color scale, the interpolation will not be doing so great (even if the result still looks quite good).

    Without interpolation

    library(ggplot2)
    cols <- rev(rainbow(7)[-7])
    
    ggplot(faithfuld, aes(waiting, eruptions)) +
      geom_raster(aes(fill = density), interpolate = FALSE) +
      scale_fill_gradientn(colours = cols)
    

    With interpolation

    ggplot(faithfuld, aes(waiting, eruptions)) +
      geom_raster(aes(fill = density), interpolate = TRUE) +
      scale_fill_gradientn(colours = cols)
    

    With interpolation and a less complex palette

    ggplot(faithfuld, aes(waiting, eruptions)) +
      geom_raster(aes(fill = density), interpolate = TRUE) +
      scale_fill_gradientn(colours = c("steelblue", "tomato"))
    

提交回复
热议问题