4
我想要做一个按x轴上的两个离散变量排序的小平面ggplot。问题是我想让垂直相邻的条目都触摸。目前,根据哪个水平的因子位于顶部图与底部之间存在行之间的空间。对不起,这个可重复的例子有点冗长。ggplot geom_tile与小平面的间距
npats=20
simsympt=c(id=1,date=1,tx="control",sympt=0)
for(i in 1:npats)
{ days=abs(round(rnorm(1,100,40),0))
id=rep(as.character(i),days)
date=1:days
tx=rep(sample(c("control","treatment"),1),days)
sympt= sample(0:10, days,p=c(12,3,3,2,1,1,1,1,1,1,1),rep=T)
simsympt= rbind(simsympt, cbind(id,date,tx,sympt))
}
####tidy things up a bit
simsympt=data.frame(simsympt)[-1,]
colnames(simsympt)=c('id','date','tx','level')
simsympt$date=as.numeric(as.character(simsympt$date))
simsympt$level=as.numeric(as.character(simsympt$level))
#simsympt$id=as.numeric(as.character(simsympt$id))
head(simsympt)
##now the important stuff
p <- ggplot(simsympt, aes(x=date,y=id))
p= p + geom_tile(aes(fill=level)) +
facet_grid(tx~.,drop=T,space="free")+
scale_y_discrete(expand=c(0,0),drop=T)
p
所有我需要的是除去在顶部和底部图(小面)都行之间的所有的垂直空间。例如,由于ID号15在对照组中,治疗组中不应该有她的行。 谢谢, 赛斯
这工作完美。谢谢 – Seth 2012-03-08 23:28:13