I want to plot the 4 ggplot graph in a page and the 4 line in one graph within a loop. What I only can do now is the plot 4 graphs separately.
Is there any smart way to do it? thanks
library(ggplot2)
dataset1<-c(1,5,12,21,30,50,90,100)
dataset2<-c(10,15,120,210,300,50,90,100)
dataset3<-c(1,5,12,21,30,50,900,1000)
Date = c("2020/07/16","2020/07/23","2020/07/30","2020/08/06","2020/08/13","2020/08/20","2020/08/27","2020/09/13")
datatotal<-c(dataset1,dataset2,dataset3)
Groups<-3
datamatrix1<-matrix(datatotal,length(dataset1),Groups)
plot1g<-function(dataset)
{y<-dataset/10*dataset[1]
df <- data.frame(y, Date = as.Date(Date))
ggplot(df) + aes(Date, y) + geom_line()}
plot4g<-function(datamatrix)
{
for(i in 1:dim(datamatrix)[2])
{
print(plot1g(datamatrix[,i]))
}}
plot4g(datamatrix1)