I wrote the following script to generate several plot in a for loop which works well:
stat <- list.files("D:/...", pattern = "met")
par(mfrow = c(4, 4))
for (x in stat) {
plot((assign(x, read.csv(x, head=TRUE, sep=""))),typ="l", col="red")
}
What I would like to achieve now is to add the title of each graph recursively according to the name of the file that is read.
Hope this is clear,
Best,
P.S.
I also have another curiosity but I will leave this maybe for after.
Thanks.
Does adding the title (
main) argument toplotdo what you’re looking for?edited for OPs comment
you can use
gsubfor this.However, the looping assign construct you’re using is a dangerous one to get in the habit of using. Usually this would be done by reading all the files in as a list and then
lapplyacross them, or some variation on that theme.You should be able to skip the
assignstep altogether unless you’re doing additional processing after this plot step.