r - 单元格之间的ggplot图 block 线

标签 r ggplot2 heatmap

我正在使用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

(对不起,不能发布任何图片)
谢谢!

最佳答案

只需将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")

将为您提供此图,并在图块之间加上线条:enter image description here

您可以使用size来放大或缩小线条,和/或使用color = white

关于r - 单元格之间的ggplot图 block 线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32665431/

相关文章:

RStudio 需要很长时间才能显示 ggplot 图

r - 如何在 ggpairs (R) 中显示带有 scale_colour_manual 的彩色组相关性?

r - 在ggplot2之上覆盖基本R图形

python - Matplotlib:如何使背景透明?

python - 为来自 Pandas 数据框的轨迹数据绘制热图

RStudio 本地 + R 云

r - 根据上面满足条件的第一行改变值

r - 过滤数据框

R ggplot2 : overlaying multiple geom_ribbon objects in a single plot using a nested loop

r - 绘制第三维热图