I am plotting multiple plots:
a <- dir(pattern="stuff.*\\.txt$")
for (i in 1:length(a)) {
b <- read.table(a[i])
jpeg(paste("/../.../", i, ".jpg"))
plot(b$V1,b$V2, main=?)
dev.off()
}
I want to name all jpg & main=? with original file name. All jpgs from this code are named from 1 to N. Is their any way to do this?
Perhaps I’m missing something, but the variable
a[i]is the original data file name. So you just need to do:In your ‘paste’ function, the default separator is a space, so:
gives
A B. Instead, you want:paste(A,B, sep=""). When creating the jpeg file you should remove the.txtor.csvfile extension from your data. So something like:Should work