I'm quite new to R, and came across a problem I can't solve based on my knowledge/books/internet.
So here is the problem:
I've got 60 csv files, for which I want to plot a scatter plot each. They're all formatted the same, so I should (theoretically) be able to solve this task with a nice loop. Here is my code:
library(tools)
library(ggplot2)
files = dir('~/Klima_hist_CPL/tillnov/ClimDatK1/*.csv')
for (Y in list.files(path = "~/Klima_hist_CPL/tillnov/ClimDatK1/",pattern =".csv",
all.files = FALSE, full.names = TRUE, recursive = FALSE,
ignore.case = FALSE, include.dirs = FALSE, no.. = FALSE)){
myData<-read.csv(Y)
pdf("~/Klima_hist_CPL/tillnov/ClimDatK1/mypdf.pdf", width = 4, height = 4)
print(ggplot(data = myData, aes(ACTION_DATE, TEMP))
+ geom_point(aes(x = myData$ACTION_DATE, y = myData$TEMP_SET),colour=('blue'))
+ geom_point(aes(x = myData$ACTION_DATE, y = myData$TEMP_MEASURED), colour=('red') ))
#newFilename <-paste(file_path_sans_ext(basename(Y)),".jpg")
#fp <-paste('~/Klima_hist_CPL/tillnov/ClimDatK1/',newFilename)
#writeJPEG(output,file=fp,append=FALSE)
dev.off()
}
As you can see I tried around a bit and used fragments of code from previous tasks. Unfortunately they don't work when combined.
Summing up:
- Multiple CSV files
- all formatted the same
- each one should be plotted
- I do not care if this results in one pdf or 60 of them