I have a list of dataframes that I want to filter and get a list of their plots. I have provided the 3 df of my lists and the 10 first rows of every df
library(dplyr)
library(survival)
library(survminer)
df_list<-list(STAT5A = structure(list(Months = c(114.3333333, 257.7666667,
242.5666667, 240.4333333, 117.5333333, 153.9666667, 131.0666667,
67.46666667, 2.5, 271.2666667), Evento = c(0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L), Gen.Alt = c("Low.Amp650", "Low.Amp650",
"Low.Amp650", "Low.Amp650", "Low.Amp650", "Low.Amp650", "Low.Amp650",
"Low.Amp650", "Low.Amp650", "Low.Amp650")), row.names = c("MB-0508",
"MB-3122", "MB-5190", "MB-5444", "MB-7109", "MB-0062", "MB-0218",
"MB-0500", "MB-0522", "MB-2801"), class = "data.frame"), THBD = structure(list(
Months = c(214.7, 242.5666667, 243.1666667, 117.5333333,
153.9666667, 114.6, 261.2, 163.5333333, 200.1333333, 234.4
), Evento = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), Gen.Alt = c("Low.Amp650",
"Low.Amp650", "Low.Amp650", "Low.Amp650", "Low.Amp650", "Low.Amp650",
"Low.Amp650", "Low.Amp650", "Low.Amp650", "Low.Amp650")), row.names = c("MB-3600",
"MB-5190", "MB-5366", "MB-7109", "MB-0062", "MB-0605", "MB-2984",
"MB-5327", "MB-5541", "MB-5566"), class = "data.frame"), PER2 = structure(list(
Months = c(239.3, 262.6333333, 282.3666667, 78.76666667,
153.9666667, 131.0666667, 67.46666667, 76.7, 97.26666667,
243.7666667), Evento = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L), Gen.Alt = c("Low.Amp650", "Low.Amp650", "Low.Amp650",
"Low.Amp650", "Low.Amp650", "Low.Amp650", "Low.Amp650", "Low.Amp650",
"Low.Amp650", "Low.Amp650")), row.names = c("MB-3500", "MB-3014",
"MB-6062", "MB-0174", "MB-0062", "MB-0218", "MB-0500", "MB-0610",
"MB-0658", "MB-3395"), class = "data.frame"))
loop<-c(1:length(df_list))
Alteraciones<-c("Low.Amp650","Low","High")
survival<-function(i){
Gen.Surv<-df_list[[i]]
s<-filter(Gen.Surv,Gen.Alt%in%Alteraciones[c(1:2)])
a.km <- survfit(Surv(Months, Evento) ~ Gen.Alt, data = s, type = "kaplan-meier")
plot_i<-ggsurvplot(a.km, conf.int=FALSE)
}
graphs<-lapply(loop,FUN=survival)
arrange_ggsurvplots(graphs,nrow=2,ncol=2)
But I get the following error
Error in eval(fit$call$data) : object 's' not found
Called from: eval(fit$call$data)
Error during wrapup: unimplemented type (29) in 'eval'
Error: no more error handlers available (recursive errors?); invoking 'abort' restart
Error during wrapup: INTEGER() can only be applied to a 'integer', not a 'unknown type #29'
Error: no more error handlers available (recursive errors?); invoking 'abort' restart
For some reason, this chunk of code is not working
Gen.Surv<-df_list[[i]]
s<-filter(Gen.Surv,Gen.Alt%in%Alteraciones[c(1:2)])
But if I run it this way it works well (1 instead of i)
x<-df_list[[1]]
y<-filter(x,Gen.Alt%in%Alteraciones[c(1:2)])
a.km <- survfit(Surv(Months, Evento) ~ Gen.Alt, data = y, type = "kaplan-meier")
plot_1<-ggsurvplot(a.km, conf.int=FALSE)
graphs<-list(plot_1,plot_2,plot_3)
arrange_ggsurvplots(graphs,nrow=2,ncol=2)
I could make it work for every plot, one by one but what if I had more DF? I would like to get my 3 different plots like this I would appreciate any help.