Stacking multiple plots, vertically with the same x axis but different Y axes in R

前端 未结 4 573
既然无缘
既然无缘 2020-12-24 14:39

I have a data.frame with multiple time series vectors against a date:time vector. I would like to plot all of the relevant vectors, vertically stacked on separate graphs wit

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-24 15:18

    If you want to be old-fashioned you can use lattice. Unlike @aaronwolen I assumed there was a missing time variable in the data set, so I made one up:

    dt$time <- seq(nrow(dt))
    library(reshape2)
    mm <- melt(subset(dt,select=c(time,DEPTH,X,Y,Z)),id.var="time")
    library(lattice)
    xyplot(value~time|variable,data=mm,type="l",
           scales=list(y=list(relation="free")),
           layout=c(1,4))
    

    enter image description here

提交回复
热议问题