Multi Plot by ggplot

Multi Plot by ggplot
-
```{r,message=F,error=F,warning=F}
## source - http://www.cookbook-r.com/Graphs/Multiple_graphs_on_one_page_(ggplot2)/
multiplot <- function(plotlist=NULL, file, cols=1, layout=NULL) {
#require(grid)
#plots <- c(list(...), plotlist)
numPlots = length(plots)
if (is.null(layout)) {
layout <- matrix(seq(1, cols * ceiling(numPlots/cols)),
ncol = cols, nrow = ceiling(numPlots/cols))
}
if (numPlots==1) {
print(plots[[1]])
} else {
grid.newpage()
pushViewport(viewport(layout = grid.layout(nrow(layout), ncol(layout))))
for (i in 1:numPlots) {
matchidx <- as.data.frame(which(layout == i, arr.ind = TRUE))
print(plots[[i]], vp = viewport(layout.pos.row = matchidx$row,
layout.pos.col = matchidx$col))
}
}
}
## source - http://www.cookbook-r.com/Graphs/Multiple_graphs_on_one_page_(ggplot2)/
library(ggplot2)
library(scales)
library(grid)
plots<-list()
for(ddd in 1:cnt){
tmp<-na.omit(df.data[[ddd]])
colnames(tmp)[2]<-"value"
g<-ggplot(tmp,aes(x=date,y=value))
g<-g+geom_line()
g<-g+scale_x_date(labels=date_format("%Y/%b"))
g<-g+ggtitle(colnames(df.data[[ddd]])[2])
g<-g+geom_smooth(method=lm)
g<-g+geom_smooth(method=loess,color="red")
g<-g+geom_point()
plots[[ddd]]<-g
}
multiplot(plotlist=plots,cols=2)
```

Source/Reference
http://www.cookbook-r.com/
http://www.cookbook-r.com/Graphs/Multiple_graphs_on_one_page_(ggplot2)/