1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
work<- setwd("C:/Users/Cesar/Desktop/global")
graphe<- setwd("C:/Users/Cesar/Desktop/global/graphe")
library(ggplot2)
my_plot <- function (df, x, y)
{
ggplot(df, aes_string(x=x, y=y))+
geom_point()+
geom_smooth(method=lm, colour="red", fill="red", alpha=0.25) +
theme_classic ()
}
setwd(work)
files <- list.files(path = "data", pattern = (".csv$"))
for (k in 1:length(files)) {
fname <- files[k]
cat(paste0("Now analyse data/", fname, "...\n"))
data <- read.csv2(paste0("data/", fname), header = T, stringsAsFactors = F, dec = ",")
setwd(graphe) #faire 1dossier par fichier
newdir <- paste0(fname)
dir.create(newdir)
for(i in 2:ncol(data)){
cwd <- getwd()
setwd(newdir)
jpeg(paste(names(data)[i], "jpeg", sep = "."), width = 15, height =12, units="cm", quality=75, res=300)
p <- my_plot(data, names(data)[i], "score")
print(p)
dev.off()
print(p)
dev.off()
setwd(cwd)
}
setwd(work)
} |
Partager