Alessandro
Alessandro

Reputation: 1

Generating separate plots for each unique subject ID by adding abline() and lines()

I am trying to plot (a kind of) longitudinal observations by ID adding some more informations. I followed what it is stated here Generating separate plots for each unique subject ID and save them in the working directory with the subject ID number but basically I am stucked on some issues; after manipulating my initial dataset, I get:

dput(dati1[10:15,c(1,6)])
structure(list(OPERA = c("CALTAGIRONE - GELA Ripristino e ammodernamento", 
"Catania - Metropolitana", "Catania - Metropolitana", "Catania - Metropolitana", 
"Catania - Metropolitana", "Catania - Metropolitana"), Finanziato_cumulato = c(2.65e+08, 
9e+07, 1.9e+08, 3.14e+08, 7.16e+08, 8.31e+08)), row.names = c(10L, 
11L, 14L, 13L, 12L, 15L), class = "data.frame")
dput(dati2[100:114,c(1,6,10)])
structure(list(OPERA = c("CALTAGIRONE - GELA Ripristino e ammodernamento", 
"CALTAGIRONE - GELA Ripristino e ammodernamento", "CALTAGIRONE - GELA Ripristino e ammodernamento", 
"CALTAGIRONE - GELA Ripristino e ammodernamento", "CALTAGIRONE - GELA Ripristino e ammodernamento", 
"Catania - Metropolitana", "Catania - Metropolitana", "Catania - Metropolitana", 
"Catania - Metropolitana", "Catania - Metropolitana", "Catania - Metropolitana", 
"Catania - Metropolitana", "Catania - Metropolitana", "Catania - Metropolitana", 
"Catania - Metropolitana"), DataPubblicazione = structure(c(18955, 
19010, 19018, 19101, 19205, 18208, 17555, 16392, 16392, 17330, 
18710, 18878, 18989, 19216, 19220), class = "Date"), Pubblicato_cumulato = c("1673547.8", 
"1673547.8", "1673547.8", "1673547.8", "1673547.8", "384812358.81", 
"497236813.29", "498686813.29", "499936813.29", "499936813.29", 
"502296318.06", "502296318.06", "502296318.06", "504833868.06", 
"510713868.06")), row.names = c(103L, 93L, 95L, 92L, 98L, 105L, 
110L, 107L, 112L, 113L, 114L, 109L, 106L, 111L, 108L), class = "data.frame")
dput(dati4[c(83,105),])
structure(list(OPERA = c("CALTAGIRONE - GELA Ripristino e ammodernamento", 
"Catania - Metropolitana"), Data_Commissario = structure(c(19123, 
18844), class = "Date")), row.names = c(83L, 105L), class = "data.frame")
lst1 <- split(dati1, dati1$OPERA)
pdf('CUP.pdf')
invisible(lapply(lst1, function(sub) with(sub,                                        plot(sort(DATA_GENERAZIONE_COMPLETO), sort(Finanziato_cumulato), type='l',pch=20, col='darkblue',main= OPERA[1]))))
dev.off()

to get a plot for every dati1$OPERA;

what I am tryng to add is

abline(v=dati4$DataCommissario,col='green')

(which is unique for every 'OPERA') and

lines(dati2$DataPubblicazione, dati2$Pubblicato_cumulato],type='l',col='deeppink')
 

inside the line for plot(), but until now no solutions came to me; should I split(dati2) and split(dati4) and neste lapply() two times to get abline() and lines() as I am trying to do? Any suggestion?

Upvotes: 0

Views: 55

Answers (0)

Related Questions