I have a problem with this code.
When I draw just one plot, I have title and when I draw seven plots, I have no title to each plot.
Could you help me ?
> TU <- readRDS("TU.rds")
> View(TU)
> head(TU)
IDFOURNEE NUMFOUR TOTALTAP VALIDFAB DATEHEUREDEBUT DATEHEUREFIN MATERIAUX TRAITEMENT FAMILLEPIECE1 FAMILLEPIECE2
1 F31-2017/01/02-2 F31 180 1 2017-01-02 13:53:00 2017-01-02 18:55:00 Titane Recuit VIROLE
2 F31-2017/01/02-3 F31 600 1 2017-01-02 20:19:00 2017-01-03 02:24:00 Alliage_resistant_chaud_Ni_Co MES_tremp TOLE
3 F31-2017/01/03-1 F31 15 1 2017-01-03 03:26:00 2017-01-03 10:00:00 Alliage_resistant_chaud_Ni_Co MES_tremp
4 F31-2017/01/03-2 F31 400 1 2017-01-03 10:16:00 2017-01-03 16:34:00 Alliage_resistant_chaud_Ni_Co MES_tremp TOLE
5 F31-2017/01/03-3 F31 690 1 2017-01-03 17:42:00 2017-01-04 06:48:00 Alliage_resistant_chaud_Ni_Co Revenu CARTER
6 F31-2017/01/04-1 F31 280.8 1 2017-01-04 14:17:00 2017-01-04 19:57:00 Acier_faiblement_alliés Revenu CARTER
FAMILLEPIECE3 FAMILLEPIECE4 FAMILLEPIECE5 FAMILLEPIECE6 TempsUtil heureDebut momentJournee JourLettre Jour
1 5.033333 13 Matin lun 1
2 6.083333 20 Apres-midi lun 1
3 6.566667 3 Soir mar 2
4 6.300000 10 Matin mar 2
5 13.100000 17 Apres-midi mar 2
6 5.666667 14 Apres-midi mer 3
f2C <- function(ValidFab) {
TU <- readRDS("TU.rds")
if (ValidFab) {
TU <- TU[TU$VALIDFAB==0,]
}
TU$JourLettre <- factor(TU$JourLettre,levels=c("lun","mar","mer","jeu","ven","sam","dim"))
for (i in c("lun","mar","mer","jeu","ven","sam","dim")) {
assign(paste0("TU",i),TU[TU$JourLettre==i,])
assign(i,
ggplot(get(paste0("TU",i)),aes(x=TempsUtil)) +
stat_ecdf(geom = "point") + coord_cartesian(xlim=c(0,24)) +
geom_hline(yintercept = 0.8,color="red") +
geom_hline(yintercept = 0.5,color="blue") +
theme_linedraw() + annotate(geom="text",x=12,y=0.1,label=i) + ggtitle(i) +
annotate(geom="text",x=2,y=.85,label = round(quantile(get(paste0("TU",i))$TempsUtil,0.8),2),col="red") +
annotate(geom="text",x=7,y=.55,label = round(quantile(get(paste0("TU",i))$TempsUtil,0.5),2),col="blue") +
theme(strip.background = element_rect(fill="white",colour="white"),
strip.text = element_text(color="black")))
assign(i,ggplotly(get(i)))
}
if (ASauvegarder) {
if (ValidFab) {
AAfficher <- subplot(lun,mar,mer,jeu,ven,sam,dim, nrows=3,heights=c(0.3,0.3,0.3),margin=0.023) %>%
layout(title="Temps d'utilisation en cumule par jour avec ValidFab=0")
nf <- paste0(year(now()),"-",month(now()),"-",day(now())," ",hour(now()),"h",minute(now()))
setwd(paste0(repExe,"/f2CV"))
htmlwidgets::saveWidget(as_widget(AAfficher),paste0(nf, ".html"))
setwd(repExe)
AAfficher
} else {
AAfficher <- subplot(lun,mar,mer,jeu,ven,sam,dim, nrows=3,heights=c(0.3,0.3,0.3),margin=0.023) %>%
layout(title="Temps d'utilisation en cumule par jour")
nf <- paste0(year(now()),"-",month(now()),"-",day(now())," ",hour(now()),"h",minute(now()))
setwd(paste0(repExe,"/f2C"))
htmlwidgets::saveWidget(as_widget(AAfficher),paste0(nf, ".html"))
setwd(repExe)
AAfficher
}
} else {
if (ValidFab) {
subplot(lun,mar,mer,jeu,ven,sam,dim, nrows=3,heights=c(0.3,0.3,0.3),margin=0.023) %>%
layout(title="Temps d'utilisation en cumule par jour avec ValidFab=0")
} else {
subplot(lun,mar,mer,jeu,ven,sam,dim, nrows=3,heights=c(0.3,0.3,0.3),margin=0.023) %>%
layout(title="Temps d'utilisation en cumule par jour")
}
}
}
> lun
> AAfficher