I have a list dat.list of data frames that look like this:
    GeneId  baseMean    log2FoldChange  lfcSE   stat    pvalue  padj    threshold   type    sigtype
    18S_rRNA:18S_rRNA   1209166.39919685    -0.209458177840739  0.234737554962532   -0.892307913295647  0.372227913902729   0.448713101690961   non-sig other   non-sig-other
    28S_rRNA:28S_rRNA   2592930.17340529    -0.180545589669893  0.231050649278924   -0.781411306280031  0.434560623435828   0.513996436321948   non-sig other   non-sig-other
    5.8S_rRNA:5.8S_rRNA 766069.47551055 0.113601345777545   0.191275069218117   0.593916113803629   0.552568220875051   0.615519030848158   non-sig other   non-sig-other
    5S_rRNA:5S_rRNA 2.79711958523178    -1.58909406740344   1.16966935304225    -1.3585839992048    0.174278448339169   0.238886346633129   non-sig other   non-sig-other
    MS2-RNA-control1:MS2-RNA-control1   81986.8654716761    -1.52675604546698   0.617811342665657   -2.47123343329943   0.0134647893998128  0.0283469250522374  sig other   sig-other
    MS2-RNA-control2`:MS2-RNA-control2  4610.31645194732    -4.54922459870619   0.929798724392121   -4.89269825755069   9.94628389868329e-07    4.37636491542065e-06    sig other   sig-other
I want to generate an MA plot for each data frame using this function:
maplot <- function(df) {
  ggplot(df, 
    aes(x = baseMean, y = log2FoldChange)) +
    scale_x_continuous(trans = "log10") +
    geom_point(aes(col = threshold), size = 1, shape = 20) +
    scale_color_manual(values = c("non-sig" = "gray70","sig" = "red")) +
    geom_point(data = df[df$sigtype == 'sig-haca', ], pch = 21, fill = NA, size = 3, colour = "blue", stroke = 0.5) +
    ylim(-5, 10) +
    geom_hline(yintercept = 0, linetype = "dashed", color = "black") +
    xlab("mean of normalized counts") + 
    ggtitle(paste("MAPLOT_", titlename, sep = "")) +
    theme_classic()
}
I have tried lapply(dat.list, maplot), but that doesn't work. How do I specify titlename in the ggtitle call?
 
    