单元格之间的ggplot平铺线

ggplot tile line between cells

我正在使用 ggplot 和 geom_tile 来形成热图。我希望在单元格之间插入一些微弱的线条。

例如:

我的 ggplot geom_tile 热图:

library(ggplot2)
library(reshape2)
data("iris")
x = melt(cor(iris[,1:4]))
ggplot(data=x,aes(Var1,Var2,fill=value)) + geom_tile() # No line between the cells

我想要的(来自 R 中的 d3heatmap 包)

library(d3heatmap)
data("iris")
x = cor(iris[,1:4])
d3heatmap(cor(iris[,1:4]),Rowv = F,Colv = F) #There is a faint line between the cells

(抱歉不能post任何图片) 谢谢!

只需将 color = "gray" 添加到您的 geom_tile

library(ggplot2)
library(reshape2)
data("iris")
x = melt(cor(iris[,1:4]))
ggplot(data=x,aes(Var1,Var2,fill=value)) + 
  geom_tile(color = "gray")

会给你这张图,方块之间有线:

您可以使用 size 使线条变大或变小,and/or 使用 color = white