Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ggplot tile line between cells

Tags:

r

ggplot2

heatmap

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!

like image 782
Kevin Avatar asked Sep 19 '15 07:09

Kevin


1 Answers

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:enter image description here

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

like image 124
RHA Avatar answered Oct 02 '22 19:10

RHA