Hello,
I would like to get some advice and help on an idea.
At the moment, I can print my different plots in a PDF document with one plot per page for each of my leaders :
for (my_leader in my_leaders_list){
pdf(file = paste0(dir,"/figs/PCA_PI_",my_leader,".pdf"))
barplot(...)
acp2d(....)
for (patients in patients_list_of_<my_leader>){
print(ggplot(......))
}
dev.off()
}
dev.off()
As you can see on the simplified code, there is a barplot, a ggplot acp representation, one or more ggplots depending on the length of the patient list of each leader.
Leader_1 : patient1, patient2, patient3
Leader_2 : patient1
Leader_3 : patient1, patient2
,etc.
My idea is the following : I want my plots to be on a single pdf page for each of my leaders
I was able to produce at least this :
with :
for (my_leader in my_leaders_list){
pdf(file = paste0(dir,"/figs/PCA_PI_",my_leader,".pdf"))
plot1=acp2d(...)
ggp = list()
for (patients in my_patients_leader_list){
for (i in 1:length(my_patients_leader_list){
ggp[[pi]]=ggplot(.....)
}
}
grid.arrange(plot1,ggp[[pi]],nrow=2)
}
I have my acp plot and my plot of the last patient of each leader arranged on my page but several levels of difficulty appear to me for the next step :
-
loops : I know that r is not made for loops (I still have many bad manners related to python programming) and that there is lapply for example. But I don't know how to apply this tool on my code
-
I can't create a list of my patient plots to give to grid.arrange if it's possible
-
I also tried the version with the cowplot and patchwork packages
-
I sometimes get errors about "grob" : the barplot() format seems to be problematic for grid.arrange for exemple. What is it and when should I convert ggplot to "grob" ?
Thank you for your patience and interest in this beginner's post !