Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep or remove grey margin for geom_tile on all facets? [duplicate]

Tags:

r

ggplot2

You can see on one group there is horizontal grey margin, on the other there is none.

How can I make the margin consistent across the facets?enter image description here

expand.grid(x=1:3, y=1:3)
a<-expand.grid(x=1:3, y=1:3)
a$value=rnorm(9)
a$group=1
b<-expand.grid(x=3, y=1:3)
b$value=rnorm(3)
b$group=2
c<-rbind(a,b)
ggplot(c, aes(x=factor(x), y=factor(y), fill=value)) + 
  geom_tile() + facet_grid(.~group, scale="free_x", space="free_x")
like image 405
colinfang Avatar asked Sep 24 '13 10:09

colinfang


1 Answers

You should add expand=c(0,0) inside the scale_x_discrete() and scale_y_discrete() to remove grey area.

  +scale_x_discrete(expand=c(0,0))+
  scale_y_discrete(expand=c(0,0))
like image 132
Didzis Elferts Avatar answered Oct 19 '22 10:10

Didzis Elferts