I have a time series data file which has the concentration of 4 metabolites A, B, AE and E over time. I have many data files of this type (around 100). I want to plot the time series for all the four metabolites in all the files in one graph. Each metabolite is assigned a specifc color.
I compiled the below code, however it plots data in only one file (the last one). I think that is because when ever I call ggplot() it creates a new plot. I've tried creating the plot outside of the four loop and it didn't work.
p = NULL
for(i in 1:length(filesToProcess)){
fileName = filesToProcess[i]
fileContent = read.csv(fileName)
#fileContent$Time <- NULL
p <- ggplot()+
geom_line(data = fileContent, aes(x = Time, y = A, color = "A"), size =0.8) +
geom_line(data = fileContent, aes(x = Time, y = B, color = "B"), size =0.8) +
geom_line(data = fileContent, aes(x = Time, y = AE, color = "AE"), size =0.8) +
geom_line(data = fileContent, aes(x = Time, y = E, color = "E"), size =0.8) +
xlab('Time') +
ylab('Metabolite Concentration')+
ggtitle('Step Scan') +
labs(color="Metabolites")
}
plot(p)
Sample files can be found here

