I'm using data in a format shown: Actual data set much longer. Column labels are: Date | Variable 1 | Variable 2 | Failed ?
I'm sorting the data into date order. Some dates may be missing, but an ordering function should be sorting this out. From there, I'm trying to split the data into sets where new sets are denoted by the far right column registering a 1. I'm then trying to plot these sets on a single graph with number of days passed on the x-axis. I've looked into using the ggplot
function, but it seems to require frames where the length of each vector is already known. I tried creating a matrix of a length based on the maximum number of days that passed for all sets and then fill the spare cells with NaN
values to be plotted, but this took ages as my data set is quite large. I was wondering whether there was a more elegant way of plotting the values against days past for all sets on a single graph, and then iterate the process for additional variables.
Any help would be much appreciated.
Code for a reproducible example is included here:
test <-matrix(c(
"01/03/1997", 0.521583294, 0.315170092, 0,
"02/03/1997", 0.63946859, 0.270870821, 0,
"03/03/1997", 0.698687101, 0.253495021, 0,
"04/03/1997", 0.828754157, 0.233024574, 0,
"05/03/1997", 0.87078867, 0.214507537, 0,
"06/03/1997", 0.883279874, 0.212268627, 0,
"07/03/1997", 0.952083969, 0.062663598, 0,
"08/03/1997", 0.991100195, 0.054875256, 0,
"09/03/1997", 0.992490126, 0.026610776, 1,
"10/03/1997", 0.020707391, 0.866874513, 0,
"11/03/1997", 0.32405139, 0.778696984, 0,
"12/03/1997", 0.32665243, 0.703234151, 0,
"13/03/1997", 0.603941956, 0.362869647, 0,
"14/03/1997", 0.944046386, 0.026992527, 1,
"15/03/1997", 0.108246142, 0.939363715, 0,
"16/03/1997", 0.152195386, 0.907458966, 0,
"17/03/1997", 0.285748169, 0.765212667, 0), ncol = 4, byrow=TRUE)
colnames(test) <- c("Date", "Variable 1", "Variable 2", "Failed")
test <-as.table(test)
test