I've been trying (knowing all the reasons why I shouldn't) to overlay two graphs on each other. I remember that when I used viewports in the past the two images would overlay on top of each other. So grid
wouldn't overwrite one graphic with the other. In the MWE below, one graphic is deleted when I try and print the second over it.
What am I doing wrong? Thanks
library(grid)
library(ggplot2)
date=seq(as.Date('2012-04-01',"%Y-%m-%d"),as.Date('2013-03-27','%Y-%m-%d'),1)
tp1=data.frame(Date=date,bond=rnorm(361,100,2),equity=rnorm(361,60,15))
vp=viewport(x=0.5,y=0.5,height=1,width=1)
a = ggplot(tp1,aes(Date,bond)) + geom_line(colour=I("blue")) + xlim(range(tp1$Date))
b = ggplot(tp1,aes(Date,equity)) + geom_line(colour=I("red")) + xlim(range(tp1$Date))
print(a,vp=vp)
print(b,vp=vp)