0

I have a lapply function that applies my graphing function to each element within the list of qList (each element is a data table). Each element also already is the name of the disease.

volcanoList <- lapply(unique(qList),
                  function(x) volcanoGraph(x))

The volcanoGraph function is the following standard ggplot function:

volcanoGraph <- function(dataSetOrdered) {
ggplot(dataSetOrdered) +
    geom_point(aes(x=MeanDiff, y=-log10(qColumn), colour=threshold)) +
    geom_text_repel(aes(x = MeanDiff, y = -log10(qColumn), label= 
    ifelse(geneLabels %in% 1:10 == T | minDiff %in% 1:10 == T | maxDiff %in% 
    1:10 == T, geneMutCount,""))) +
    xlab("WT - Mutation Mean Difference") + 
    ylab("-log10 adjusted q-value") +
    #scale_y_continuous(limits = c(0,50)) +
    theme(legend.position = "none",
          plot.title = element_text(size = rel(1.5), hjust = 0.5),
          axis.title = element_text(size = rel(1.25)))
}

As of right now, there is no ggtitle attached to it, since I don't know how to make titles for each element based on its corresponding disease (based on the element name). As an expected output, I wanted to label the title for each graph with: "Graph of (insert element name here)".

NickL
  • 103
  • 6
  • Do these help https://stackoverflow.com/a/55194736/786542 & https://stackoverflow.com/a/57362627/786542? – Tung Jun 18 '20 at 16:54
  • @Tung, is it possible to do without using a forloop? – NickL Jun 18 '20 at 16:56
  • If `unique(qList)` is a named list, you could pass the indices (`x <- seq_along(unique(qList))`) of the list instead of the list to your function; this way you could would have `names(x)` and `unique(qlist)[[x]]` available within your function. – user12728748 Jun 18 '20 at 17:40
  • 1
    Something like `lapply(seq_along(unique(qList)), function(x) volcanoGraph(unique(qList)[[x]], title = names(unique(qList))[x]))`, modifying your function to accept `title` in ggtitle. – user12728748 Jun 18 '20 at 17:45
  • @user12728748 thank you! That was perfect. – NickL Jun 18 '20 at 18:08

0 Answers0