using ggplot2 inside for loop doesn't show the plots names I want to print the plots into one page and save them
I have 60 csv files each consists of two columns 1st is date and second is ssh and each has different rows number. I list them in variable called files and then I plot them. the for loop produced 60 plots. the problem is how to know the name of those plots to call them when I want e.g. to print 4 plots in one page so I will have at the end 15 pages each contains 4 plots. when I used
library(gridExtra)
grid.arrange(p1,p2,p3,p4, nrow=2,ncol=2)
grid.arrange(p5,p6,p7,p8, nrow=2,ncol=2)
and so on till p60 it showed no result. warning messages said there is no object called p1, p2,p3,p4,....p60.
the code is as follows:
files<- list.files("F:/R Practice/time series")
for (i in seq_along(files)){
mydf <- read.csv(files[i], stringsAsFactors=FALSE)
a<- data.frame(as.Date(mydf$date, "%d-%m-%y"),mydf[,-1])
names(a)[1]<- "Date"
names(a)[2]<- "SSH"
b <- zoo(a[,-1],order.by=as.Date(a[,1]))
p<- ggplot(a, aes(x=Date,y=SSH, color=SSH)) +geom_line(colour="darkblue")# +labs(title = "gridcell of (31.25N, 33.25E) ",x="Date", y="SSH")
p<-p+ggtitle(readline(prompt = "enter cell coordinates: "))+xlab("Year")+ylab("weighted average SSH of center cell")
# adding atrribute to the plot p[i]
p<-p+theme(axis.title.x=element_text(color = "black",size = 12),
axis.title.y=element_text(color = "black",size = 8),
axis.text.x=element_text(color="black",size=8),
axis.text.y = element_text(color = "black",size = 8),
panel.background = element_rect(colour = "black", size=0.5 ,fill = NA),
panel.grid.minor = element_blank(),
panel.grid.major = element_blank(),
axis.line = element_line(colour = "black",size=1),
legend.position="none" ,
plot.title=element_text(hjust = 0.5,vjust= 0.5,lineheight = .3,face = "bold"))
print(p)
}