Using discrete custom color in a plotly heatmap

后端 未结 4 553
暖寄归人
暖寄归人 2020-12-18 06:28

I\'m trying to generate a plotly heatmap, where I\'d like the colors to be specified by a discrete scale.

Here\'s what I mean:

Gene

4条回答
  •  时光取名叫无心
    2020-12-18 06:49

    A nice way for creating discrete color breaks is given in question 59516054 . Given the offered Z_Breaks function, you can center the colorbar tick labels in the middle of each box by using the function:

    tickpos <- function(nFactor) {
        pos <- unique((head(Z_Breaks(nFactor), -1)) + head(Z_Breaks(nFactor))[2] / 2) * (nFactor - 1)
    }
    

    and then assigning it to the tickval argument of colorbar:

    colorbar <- list(tickvals = tickpos(nFactor), ticktext = names(colours))
    

提交回复
热议问题