ggplot tile line between cells

别说谁变了你拦得住时间么 提交于 2020-08-06 12:45:10

问题


I am using ggplot and geom_tile to form heatmaps. And I wish to insert some faint lines between the cells.

For example:

My ggplot geom_tile heatmap:

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

What I desire (from d3heatmap package in R)

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

(Sorry can't post any pictures) Thanks!


回答1:


Just add color = "gray" to your 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")

Will give you this figure with lines between the tiles:

You can play with size to make the lines bigger or smaller , and/or use color = white.



来源:https://stackoverflow.com/questions/32665431/ggplot-tile-line-between-cells

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