Sequential plot number in cowplot

Viewed 19

I have created a list of plots called plot.list within a loop and called them with different names e.g. "tissue1_gene1_gene2", "tissue1_gene3_gene4",....,"tissue2_gene1_gene2, "tissue2_gene3_gene4",...., "tissue3_gene1_gene2", "tissue3_gene3_gene4",....

I now need to create a figure and have before each set of plots a title object that I created with draw_label.

I thought I could call each item in my plot.list by its name using grep, but this doesn't seem to work.

Alternatively, I could call a sequential number of plots based on the number of e.g. "tissue1_" or "tissue2_" items, without writing out each number. Is there a way to do achieve any of these?

Here below, my current code, which I would like to simplify/have it less repetitive.

Joint_figure = plot_grid(plot_grid(title1,
                                   plot.list[[1]],
                                   plot.list[[2]],
                                   plot.list[[3]],
                                   plot.list[[4]],
                                   plot.list[[5]],
                                   plot.list[[6]],
                                   align = "h", ncol = 7, rel_widths = c(0.1, rep(1, 6))),
                         plot_grid(title2,
                                   plot.list[[7]],
                                   plot.list[[8]],
                                   plot.list[[9]],
                                   plot.list[[10]],
                                   plot.list[[11]],
                                   plot.list[[12]],
                                   align = "h", ncol = 7, rel_widths = c(0.1, rep(1, 6))),
                         plot_grid(title3,
                                   plot.list[[13]],
                                   plot.list[[14]],
                                   plot.list[[15]],
                                   plot.list[[16]],
                                   plot.list[[17]],
                                   plot.list[[18]],
                                   align = "h", ncol = 7, rel_widths = c(0.1, rep(1, 6))),
                         align = "h", nrow = 3)

Thank you!

0 Answers
Related