How to put black borders in heatmap in R

∥☆過路亽.° 提交于 2019-12-02 21:14:16

If you follow the tutorial from Learn R blog and change the color in this paragraph to black, you will get:

(p <- ggplot(nba.m, aes(variable, Name)) +
    geom_tile(aes(fill = rescale), colour = "black") +
    scale_fill_gradient(low = "white",high = "steelblue"))

Try this:

 library(plotrix)

 #Build a 40 Row by 40 Column Matrix
 n <- 40
 mat <- matrix(rnorm(n*n), nrow = n)

 #Plot it
 color2D.matplot(mat, cellcolors = color.scale(mat, c(0,0.5,1), c(1,0.5,0), 0))

Have you tried using heatmap.2? It has paramaters to do just that.

require("gplots")

data <- # matrix or data frame for your data.

heatmap.2(data, 
          sepwidth=c(0.05, 0.05),  # width of the borders
          sepcolor='black',        # color of the separation lines
          )

You may need more in the parameters depending on what you want in your graphs. R's help on the heatmap.2 function covers pretty much everything you need: ?heatmap.2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!