I have one plot (levelplot) from the lattice library, and a stick plot from the oce library, and I'd like to stack them on top of each other. I'm having problems stacking these plots as I would normally using base R, and I assume it is because these are both specialized plots. Is it possible to stack the two below plots on the same page so that the timestamps (x axis) line up with each other?
library(oce)
library(lattice)
library(grid)
First Plot (example from help docs of OCE)
# Oceanographic example
data(met)
t <- met[["time"]]
u <- met[["u"]]
v <- met[["v"]]
p <- met[["pressure"]]
dev.new(width=15, height=4)
plotSticks(t, 99, u, v, yscale=25)
Second plot:
AllT<-NULL
for(i in seq(1,length(t))){
myTime<-t[i]
myTime2<-rep(myTime,10)
AllT<-append(AllT,myTime2)
}
myY<-NULL
for(j in seq(1,length(t))){
mySeq<-seq(1,10)
myY<-append(myY,mySeq)
}
Temp<-seq(1,7200)
MyDF<-data.frame(Temp,myY,AllT)
#Plot code
dev.new(width=15, height=6)
p1<-levelplot(Temp ~ AllT * myY,
data = MyDF,ylim=c(10,1),
xlab = "Time", ylab = "y]",
aspect=0.4,
)
p1
trellis.focus("legend", side="right", clipp.off=TRUE, highlight=FALSE)
grid.text('[Temp]', 1.9, .5, hjust=0.5, vjust=1,rot=270)
trellis.unfocus()
Ideally, the final plot would have the stick plot on top (no need for tick labels on the stick plot if x axis are lined up), with the level plot below with minimal space in between