I have time-series data of 6 months and I want to plot it in grid manner like this
As a reproducible example, let us the following code:
library(xts)
seq <- seq(as.POSIXct("2015-03-01"),as.POSIXct("2015-03-30"), by = "60 mins")
timeseries_ob <- xts(data.frame(rnorm(length(seq),30,2)),seq)
looplength <- length(unique(.indexmday(timeseries_ob)))
par(mfrow=c(4,3))
pdf("temp.pdf")
for(i in 1:looplength){
daydata <- timeseries_ob[.indexmday(timeseries_ob)%in%i,]
plot(daydata,type="l",main="")
}
dev.off()
With this code, plots get automatically saved, but they are not in the grid manner. Each plot gets saved in different page of pdf. Is there any other way to save above plots in a grid manner automatically.
Note: I don't want to use facet_grid
, because these plots are generated within a loop and I believe with ggplot
it might become complex to draw.
You have to use the par(mfrow = c(4,3))
command between pdf(...)
and dev.off()
.
This will lead to your desired result!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.